1

I'd like to understand the principles of adding methods to RTTI (I mean the old one, which is supported by old Delphi versions (before Delphi 2010) or by FPC). As far as I know the RTTI is supposed to have information about published methods. But the following example doesn't work in my case:

{$M+}
  TMyClass = class  
    published
      procedure testfn(a,b,c: Integer);
  end;
{$M-}

...

procedure TMyClass.testfn(a,b,c: Integer);
begin
    ShowMessage('s');
end;

...

GetPropInfo(TMyClass, 'testfn'); // returns nil

I'd like to understand what I need to change to receive PPropInfo for the method.

I want to get the PTypeInfo for the method. In case of a property it can be retrieved via

PropInfo := GetPropInfo(...); 
TypeInfo := PropInfo^.PropType; 
TypeData := GetTypeData(TypeInfo);

I need something like that for methods.

Int0h
  • 71
  • 5
  • 2
    [`GetPropInfo`](http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/TypInfo_GetPropInfo@PTypeInfo@string.html) is used for properties not for methods... – whosrdaddy Apr 05 '16 at 12:36
  • @whosrdaddy okay, I need the equivalent of it then. Eventually I want to get TTypeData for the method. – Int0h Apr 05 '16 at 12:45
  • 2
    What you need is [Method Address](http://docwiki.embarcadero.com/Libraries/Seattle/en/System.TObject.MethodAddress) – Dalija Prasnikar Apr 05 '16 at 12:45
  • @DalijaPrasnikar as far as I understand [Method Adress](http://docwiki.embarcadero.com/Libraries/Seattle/en/System.TObject.MethodAddress) returns a pointer to **procedure of object** (or something like that). But I need RTTI structure **TTypeData** for the method. – Int0h Apr 05 '16 at 12:55
  • 8
    http://hallvards.blogspot.com/2006/09/extended-class-rtti.html. – LU RD Apr 05 '16 at 13:00
  • I guess I commented about at same time you did. Yes, `MethodAddress` is not what you want. – Dalija Prasnikar Apr 05 '16 at 13:07
  • Very difficult to know what you are after here. A method is not a property. – David Heffernan Apr 05 '16 at 16:42
  • The RTTI is there because an eventhandler property can have a (published) method as value. But for that there is methodaddress afaik, other ways are D2010+ and not (yet) supported by FPC – Marco van de Voort Apr 11 '16 at 11:35

1 Answers1

0

Have a look at the mORMot Framework. It includes a whole bunch of additional RTTI helper functions including the very handy TMethodInfo object along with this handy function to populate it.

/// retrieve a method RTTI information for a specific class
function InternalMethodInfo(aClassType: TClass; const aMethodName: ShortString): PMethodInfo;