[fpc-pascal] How can I get a typeinfo by address?

silvioprog silvioprog at gmail.com
Fri Jul 17 16:57:37 CEST 2015

On Fri, Jul 17, 2015 at 11:33 AM, Michael Van Canneyt <
michael at freepascal.org> wrote:
> On Fri, 17 Jul 2015, silvioprog wrote:
>  Hello,
>> I need to call a method dynamically by its name over string and pass some
>> parameters to it. OK, I don't know if it is possibly in the current version
>> of the compiler, but I'm trying to do something
>> like this:
>> TMethodInvoker.Invoke(VMyObj, ['Param 1', 'Param 2', 1, True]);
>> I already get some paramerter informations using this code[1], that
>> prints all parameters and its types using RTTI.
>> So I have a question: how can I get the method typedata looking for it in
>> the VMT? Please see this:
>>   WriteLn(HexStr(@TMyObject.Test));
>>   WriteLn(HexStr(TMyObject.MethodAddress('Test')));
>> Prints the same address. But:
>>   TI := TypeInfo(@TMyObject.Test);
>>   WriteLn(HexStr(TI));
>>   TI := TypeInfo(TMyObject.MethodAddress('Test'));
>>   WriteLn(HexStr(TI));
>> Prints different results.
> You cannot get typeinfo like that for methods.
> You need to call GetPropInfo() from the typeinfo unit for published
> properties/methods.


Yes, I'm just trying to avoiding an additional declaration of my procs,
calling my methods using something like "published MyMethod(AParams: array
of ...)" instead of calling events like "type TMyProc = procedure(AParams:
array of ...) of object ...... published OnMyProc: TMyProc" etc.

> How System.TypeInfo retrieve the typeinfo from my @TMyObject.Test address?
>> It is done by the method address so?
> No.


 I took a look at the TRTTIWriter class and also in the VMT, but I don't
>> know how the compiler handles this informations internally, so sorry it
>> this question sounds nonsense. =P
> You can check the reader class in classes unit.

I'll do it again, thank you. =)

Silvio Cl├ęcio
My public projects - github.com/silvioprog
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20150717/18e22533/attachment.html>

More information about the fpc-pascal mailing list