Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DWScript: using an event in an exposed Delphi class

I exposed a Delphi class to the scripts using TdwsUnit.ExposeRTTI method. It works very well with basic data types.

However it doesn't work when I add a TNotifyEvent. My Delphi class has an OnChange : TNotifyEvent property and when assigning this OnChage in a script, I get an error

"Syntax Error: More arguments expected!"

It looks like the script compiler understand I want to call the event Handler instead of assigning the OnChange property. Add an "@" sign doesn't help.

How can my Delphi object have an event Handler having his handler code in a script ?

Regards.

like image 756
fpiette Avatar asked May 13 '13 09:05

fpiette


1 Answers

I worked around the problem by using Windows messages. My script is now using a message pump and the exposed instances post some custom messages to signal the script that an event has occured. Then the script call back Delphi code to get details. Of course I had to implement GetMessage / PeekMessage / TranslateMessage and DispatchMessage.

like image 64
fpiette Avatar answered Sep 28 '22 21:09

fpiette