Page 12 of 23

Re: COMatePLUS version 1.1

Posted: Tue Jan 19, 2010 11:06 am
by KIKI
srod wrote:Which code snippet generates the error Anthony?
See my post higher i have the same problem with PB 4.41 executing any kind of programm

Re: COMatePLUS version 1.1

Posted: Tue Jan 19, 2010 11:10 am
by srod
I have posted a bug report about this.

http://www.purebasic.fr/english/viewtop ... =4&t=40750

Re: COMatePLUS version 1.1

Posted: Sat Jan 23, 2010 11:06 am
by KIKI
I am sorry SROD but the problem is not solved even if you start with a clean version of PB4.41. I have always the problem. It seems that your bug probelm was'nt record by fred

Re: COMatePLUS version 1.1

Posted: Sat Jan 23, 2010 1:15 pm
by srod
Kiki, this is a Purebasic bug which I have reported. Worry not, Fred will fix it.

Whilst I could easily work around this, I think it is better to wait for the bug to be fixed in Purebasic.

http://www.purebasic.fr/english/viewtop ... =4&t=40750

Re: COMatePLUS version 1.1

Posted: Sat Jan 23, 2010 6:13 pm
by SFSxOI
srod, is it possible that you could pass along the work around while waiting on the bug fix in PB?

Re: COMatePLUS version 1.1

Posted: Sat Jan 23, 2010 6:19 pm
by srod
No, but you can do it yourself if you are in need.

Switch all instances of '+', '-' for their Ascii codes etc. That should fix it.

Re: COMatePLUS version 1.1

Posted: Sat Jan 23, 2010 6:58 pm
by SFSxOI
well, thats what I meant. :)

Thanks srod :)

Re: COMatePLUS version 1.1

Posted: Sun May 09, 2010 6:36 am
by chi
Why is ExecuteJavaScript to a threaded window not working? Did I miss something :wink:

Code: Select all


IncludePath "..\"
XIncludeFile "COMatePLUS.pbi"

Enumeration
  #Win1  
  #Web1
  #B1
EndEnumeration

#URL = "javascript:document.write("+Chr(34) +"<script type='text/javascript'> function Test(v) { alert(v); return v; } </script><body><input type='button' value=' test ' onclick='window.Test(3);'></body>" +Chr(34)+");document.close()"

Define.COMateObject WebObject

Procedure.i ExecuteJavaScript(Gadget, command$) 
  Protected browser.COMateObject, documentDispatch.COMateObject, script.COMateObject
  Protected result
  browser = COMate_WrapCOMObject(GetWindowLong_(GadgetID(gadget), #GWL_USERDATA)) 
  If browser 
    documentDispatch = browser\GetObjectProperty("Document")
    If documentDispatch
      script = documentDispatch\GetObjectProperty("script")
      If script
        result = script\Invoke("eval('" + command$ + "')")
        script\release()
      EndIf  
      documentDispatch\Release()
    EndIf
    browser\Release()
  EndIf 
  ProcedureReturn result
EndProcedure

Procedure OpenWin1(param)
  
  If OpenWindow(#Win1, #PB_Ignore, #PB_Ignore, 440, 280, "win1", #PB_Window_SystemMenu|#PB_Window_MinimizeGadget|#PB_Window_TitleBar|#PB_Window_ScreenCentered)
    WebGadget(#Web1, 0, 0, 440, 250, #URL)
    While WindowEvent():Wend
    ButtonGadget(#B1, 5, 255, 95, 20, "test")
  EndIf
  
  Repeat
    event=WaitWindowEvent()
    Select event        
      Case #PB_Event_Gadget        
        Select EventGadget()
            
          Case #B1
            ExecuteJavaScript(#Web1,"window.Test(1);")
            
        EndSelect        
    EndSelect
  Until event=#PB_Event_CloseWindow
  
EndProcedure

thread=CreateThread(@OpenWin1(),0)
WaitThread(thread,3000)

Debug ExecuteJavaScript(#Web1,"window.Test(1);")

Repeat
  WaitWindowEvent(16)
  x+1
Until x=180

End
thx, chi

Re: COMatePLUS version 1.1

Posted: Sun May 09, 2010 11:26 am
by srod
The problem is that the COM object is being created in your thread and you are attempting to access it in your main process with the line :

Code: Select all

Debug ExecuteJavaScript(#Web1,"window.Test(1);")
This breaks the single threaded apartment model which Purebasic initialises. In this model you cannot pass COM objects between threads etc. This has been discussed before and Freak pointed out that Purebasic cannot use a multi-threaded apartment model because, amongst other things, OLE is not strictly threadsafe and OLE is required for things like drag-and-drop etc.

Comment the offending line out and everything works fine.

There are ways around this, in that there are COM functions designed to allow us to circumvent this limitation and to marshall an object created in one thread for use in another thread etc. This is not something I wish to implement, however, because it will only complicate matters and so few people would ever need this.

The point is that you will need to keep each object you create for exclusive use within the thread which created the object etc. I'm sure you'll find a way! :)

Re: COMatePLUS version 1.1

Posted: Sun May 09, 2010 12:28 pm
by chi
Thank you for pointing this out, srod!
Guess i´ll have to stick with the idea to use get/setwindowtitle... a little bit odd but good enough for now ;)
Or any better ideas? Anyway, thx again...

chi


edit: btw. it´s for a .dll

Re: COMatePLUS version 1.1

Posted: Sun May 09, 2010 2:41 pm
by srod
Simplest way is to send a message to the thread (via a global variable or registering your own window message etc.) instructing the thread to perform some task or other with the COM object. This way, when the main process requires access to the COM object, rather than do it directly (and cause an access error) get the thread to do it.

Re: COMatePLUS version 1.2

Posted: Fri Jul 09, 2010 8:03 pm
by srod
Update - 9th July 2010.

Version 1.2 (Purebasic 4.5 edition).

A bug in COMatePLUS' error reporting has been fixed in the Purebasic 4.5 edition of COMatePLUS. Other editions were not affected by this bug because I inadvertently created COMatePLUS for PB 4.5 from an out of date version of COMatePLUS... doh!!! How the hell I did that is beyond me? :)

See the nxSoftware site for the download.

Re: COMatePLUS version 1.2

Posted: Fri Jul 09, 2010 9:12 pm
by Kiffi
srod wrote:A bug in COMatePLUS' error reporting has been fixed in the Purebasic 4.5 edition of COMatePLUS.
thanks a lot! Image

Greetings ... Kiffi

Re: COMatePLUS version 1.2

Posted: Fri Jul 09, 2010 10:42 pm
by GeBonet
Thank you for this release :lol:
Sincerely... GeBonet

Re: COMatePLUS version 1.2

Posted: Tue Aug 17, 2010 9:18 am
by captain_skank
First a little background.

Having had to use crytsal reports I needed a way to run the report from my PB app - so kludged up a command line client in vb6 as a quick n dirty way of acheiving my aim.

This works ok but is very klinky and slow so i've been wondering if i can use the crystal report conrol via pb and then I came accross comateplus.

I've had a good read or the help and a look at the examples but I'm just not getting it so before I waste to much time I thought i'd ask the expert(s) if it's actually possible to do.

Soooo, how can i convert the following simple 2 form vb app ( form1 has a button, Command1, and the code below calls form2 which has the cr viewer control on )

Private Sub Command1_Click()

Dim crApp As CRAXDRT.Application
Dim Report As CRAXDRT.Report
Dim strSelectionfrm As String
Set crApp = New CRAXDRT.Application
Set Report = crApp.OpenReport("C:\xyz\spec_master.rpt")

Form2.CrystalActiveXReportViewer1.ReportSource = Report
Form2.CrystalActiveXReportViewer1.ViewReport
Form2.Show

End Sub

the two libraries are referenced in the project Crystal ActiveX Report Viewer Library 11.5, Crystal Reports ActiveX Designer Run Time Library 11.5

I'd be really gratefull for any and all help as this will improve my app no end and make life a whole ot easier.

Thanks

captain_s