1
votes

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.

1
GetPropInfo is used for properties not for methods... - whosrdaddy
@whosrdaddy okay, I need the equivalent of it then. Eventually I want to get TTypeData for the method. - Int0h
What you need is Method Address - Dalija Prasnikar
@DalijaPrasnikar as far as I understand Method Adress returns a pointer to procedure of object (or something like that). But I need RTTI structure TTypeData for the method. - Int0h

1 Answers

0
votes

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;