Now we've got the general idea, lets get into some code. The first thing we need to address is the issue about knowing the parameters and returns types when we finally call our method.
To handle this, we declare prototypes, just like we do for event handling.
Code: [View]
type TMyDynamicProcedure = procedure(param1:integer;param2:string) of object; TMyDynamicFunction = function(param1:string):boolean of object;
Once we have our prototypes, we are pretty much set to start implementing the actual calls. There is just one more rule that we need to be aware of... for this to work, the methods you plan on calling in this way need to be declared as PUBLISHED. This is to ensure that the required information about the methods is available at runtime.
So lets make a call. The only things we need are a couple of variables that will be used during the process and the prototypes of the methods you want to call.
The variables...
Code: [View]
var methodPtr : pointer; method : TMethod;
Anyhow, lets get the rest of the code covered. It is essentially quite simple.
The first thing we need to do is to try and locate the method we want to call. The name of this method is in the string variable 'methName'.
Code: [View]
methodPtr:=targetObject.methodAddress(methName);
Code: [View]
method.data:=targetObject; method.code:=methodPtr; TMethodPrototype(method)(params);
So, lets put this to some real use... a basic object that can be used as the basis for a versioned data store.
vBulletin Message