Delphi: Which methods are supposed to be in RTTI?

789 views Asked by At

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

There are 1 answers

0
Willo van der Merwe On

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;