But then the program will not compile.
I get the following error on VisaSession.EnableEventHandler(@VisaEventHandler); :
unit1.pas(97,51) Error: Incompatible type for arg no. 1:
Got "<procedure variable type of function(LongWord;LongWord;LongWord;Pointer):LongInt of object;StdCall>",
expected "<procedure variable type of function(LongWord;LongWord;LongWord;Pointer):LongInt;StdCall>"
Any proposal on how to fix the issue?
The API in question expects a standalone function for the event handler. So, you cannot use a
non-static class method, as its signature won't match due to the hidden
Self parameter that holds the object pointer. You
can use a
static class method instead, but you will lose access to the
Self parameter, so you will have to pass the object pointer into the event handler in another way. Presumably via the event handler's
event or
userHandle parameter (if the API provides a way to pass user-defined data into the event handler). But if not, then you'll have to use a global/thread-local variable, or a thunk, or other similar approach to pass your object pointer into the event handler externally.