Board index » delphi » Calling methods at run-time via a string

Calling methods at run-time via a string

Hi,

I am currently trying to write an interface for the VBScript engine in
delphi.

At the moment, I can read and write the properties of a component at
run-time using the Run-time type information (typinfo.pas).

However, I cannot seem to be able to do a similar thing for methods.

What i want to be able to do is call a method of a control at run-time, the
method name having been passed to me from VBScript in a string.

There seem to be two approaches, neither of which i have got to work:

i. Use the MethodAddress function of TControl to return the physical
address of the method, but then how do I call that, including parameters.

ii. The other way is to use the OLE Automation functions. AFAIK putting
methods in an Automation section of the type should generate some kind of
table which i can use to call methods. However, whenever I try to get this
table (via a function in oleauto.pas), i get returned a nil.

Any ideas?

Sasha.

sa...@rebmann.powernet.co.uk
http://users.powernet.co.uk/rebmann

 

Re:Calling methods at run-time via a string


Quote
Sasha Rebmann wrote:

> Hi,

> I am currently trying to write an interface for the VBScript engine in
> delphi.

> At the moment, I can read and write the properties of a component at
> run-time using the Run-time type information (typinfo.pas).

> However, I cannot seem to be able to do a similar thing for methods.

> What i want to be able to do is call a method of a control at run-time, the
> method name having been passed to me from VBScript in a string.

> There seem to be two approaches, neither of which i have got to work:

> i. Use the MethodAddress function of TControl to return the physical
> address of the method, but then how do I call that, including parameters.

> ii. The other way is to use the OLE Automation functions. AFAIK putting
> methods in an Automation section of the type should generate some kind of
> table which i can use to call methods. However, whenever I try to get this
> table (via a function in oleauto.pas), i get returned a nil.

> Any ideas?

> Sasha.

> sa...@rebmann.powernet.co.uk
> http://users.powernet.co.uk/rebmann

I have not worked with VBScript, so I might not be understanding
the problem.  But can you not have stand-alone functions within the
Delphi unit, and have them call the appropriate methods for you?

Then you could pass the address of those functions directly as a
parameter, and the parameters to the method as other parameters??

You would just need a translation table from whatever strings
you are being passed, mapping each to the appropriate function
address??

Other Threads