Ross Levis wrote:
In a component I'm writing, I'm loading a DLL which needs to call a function in my component. I've got this working with a global function but I would rather the function be a method inside an object so I can have access to my objects data when the call is made.
What is the signature of the function, as the DLL expects it to be? What is the signature of the method you want to call?
With some investigation, I thought I could do this: DLLOpen := TMethod(Open).Code; <<< Invalid typecast Open is a function defined in my object.
Right. Open is a method. TMethod is a record, and it reflects the layout of a "method pointer." Open is not a method pointer. Declare a method-pointer variable, and assign Open to it. Delphi should automatically take the pointer -- you shouldn't need to use the @ operator.
Once you do that, the Code field of the record will indeed be a pointer to the first instruction in your method, but it will won't work. Method pointers also have a Data field, and that holds the value that will eventually be available as Self within the body of the method. That value gets passed to the method as though it were the first parameter. Your DLL won't have that value, and even if it did, it wouldn't know to pass it as a parameter.
It's possible to convert a method into a standalone procedure at run time so the DLL could call it with all the right parameters in the expected places, but it's a bit of work, so it's best avoided.
Does the DLL allow you to pass any kind of user-data parameter, usually as a parameter called data or lparam? If so, just pass a reference to your object in that parameter.
-- Rob _______________________________________________ Delphi mailing list -> Delphi@elists.org http://www.elists.org/mailman/listinfo/delphi