about Comat event handler: how to register specified event ?

Just starting out? Need help? Post your questions and find answers here.
john lory
User
User
Posts: 10
Joined: Mon Dec 29, 2008 10:24 am
Location: web

about Comat event handler: how to register specified event ?

Post by john lory »

I wan't process flash ocx event ,the code like bellow:

Code: Select all

  FlashObject = COMate_CreateObject("ShockwaveFlash.ShockwaveFlash", GadgetID(winhd) )
Debug FlashObject
  If FlashObject
    FlashObject\SetEventHandler(@myEventCallback()) 
....
the flash ocx 's flashcall event prototype is:

Code: Select all

Public Event FlashCall(ByVal request As String) As String
It requires a string value as return , so i write event handler procedure is:

Code: Select all

Procedure.s myEventCallback(object.COMateObject, eventName.s, parameterCount)  
If eventName = "OnReadyStateChange" 
ElseIf eventName = "FlashCall"
  Debug "FlashCall,param count:" + Str(parameterCount) + ":command:" +object\GetStringEventParam(1) + ",args :" + object\GetStringEventParam(2)
  [b]ProcedureReturn "<string>ok</string>"[/b]
ElseIf eventName = "OnProgress" 
ElseIf eventName = "FSCommand"
  Debug "FSCommand  ,param count:" + Str(parameterCount) + ",request :"+object\GetStringEventParam(1)
Else
    Debug " woo,unknown event for flash ocx"
EndIf
but when i run the app, the flash can't receive the return value:"<string>ok</string>"
it is a bug for COMate?

additional, Comate SetEventHandler function register all control's event to the handler, but how i register a specified event to ONE PB's procedure? like

Code: Select all

 ...
comateObj\SetEventHandler("event name",@eventHandler)? 
for flashcall event :

Code: Select all

...
FlashObject\SetEventHandler("FlashCall",@flashCallHandler())
....
;;flashcall event handler
procedure.s  flashCallHandler(....)
...
procedurereturn "return value"
endprocedure
....
perhapse,it is a GOOD function to PB coder :D


Comate is a great works!!
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

COMate is set up to send all events to the one event procedure (this is essentially how ActiveX controls function anyhow); from here you can do what you want with them. If you wish to employ individual event procedures then you will need to code this yourself; I don't really see a problem.

COMate cannot return values from event procedures; mostly because I have not as yet encountered an ActiveX control which requires this. Most take return values through one of the parameters being sent BYREF, which COMate can handle. Adding explicit returns from event handlers will be fiddly. The easiest way would be for COMate to pass the event handler a variant structure into which the client application would be required to pass the appropriate return value etc. This avoids COMate having to worry about the type of return required etc. Before I can do this, however, I need access to an example in which an event handler is allowed to make some kind of return value and the means to test my resulting additions to COMate. If you can supply me with a demo (a flash demo would be fine, though I'd need one which fires these events) which I can work with then I'll see what I can do?
I may look like a mule, but I'm not a complete ass.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

@John Lory :

please see the latest update to COMate in which I have added all that you were after.

I must point out though that, from what I have seen on the web, the "FlashCall" event exposed by the Shockwave object does not have a return value! I may have misunderstood what I was reading (as it was MFC code etc.) but I thought I'd point this out anyhow. :)
I may look like a mule, but I'm not a complete ass.
john lory
User
User
Posts: 10
Joined: Mon Dec 29, 2008 10:24 am
Location: web

Post by john lory »

:shock: your are SUPERMAN ,srod, so quickly you replied .
sorry for my mistake,flashcall event have NOT return value :oops:
thanks you works!!
john lory
User
User
Posts: 10
Joined: Mon Dec 29, 2008 10:24 am
Location: web

Post by john lory »

srod ,for flashcall api detail information, refer bellow links please:
http://osflash.org/pipermail/osflash_os ... 02274.html
http://osflash.org/ext_howto

the calling flow:
...
register host (python,c#) callback function for flash flashcall event,
flash fire the flashcall event
execute host callback function and return result to flash
....
it is my thinking, is it right?
john lory
User
User
Posts: 10
Joined: Mon Dec 29, 2008 10:24 am
Location: web

Post by john lory »

srod wrote:@John Lory :

please see the latest update to COMate in which I have added all that you were after.

I must point out though that, from what I have seen on the web, the "FlashCall" event exposed by the Shockwave object does not have a return value! I may have misunderstood what I was reading (as it was MFC code etc.) but I thought I'd point this out anyhow. :)
you are right ,srod,flash control flashcall event has NO return value!
I made a mistake :? :oops: in fact ,the return value is returned by call flash other function :SetReturnValue in event process method,code like:

Code: Select all

....
Procedure.s Flashcall_handler(object.COMateObject, eventName.s, parameterCount)    
  ;;;;do some logic here and return value 
   ret$="<string>ok</string>"
  
    object\invoke("SetReturnValue('" + ret$ + "')"); 
  ProcedureReturn ret$
EndProcedure 
.....

  If FlashObject 
    FlashObject\SetEventHandler("Flashcall",@Flashcall_handler()) 
....
thank you for your works :P
Post Reply