Board index » delphi » RTTI, getting procedure names

RTTI, getting procedure names

I have searched the RTTI parts, but I can't find any way to extract
information about procedures/functions.

There are functions for converting between enumerated types and strings
(GetEnumValue, GetEnumName); I need something similar for
procedures/functions -- simply put, I need a GetProcName function which
returns a name for a procedure pointer.

I am aware of the old trick of looking up the procedure address in the MAP
file. Anybody got some working code which does this? I have no wish to
"reinvent the wheel" so to speak.

--
Alexander Staubo      Professional developer, web designer, purveyor of
a...@intertele.no     epic thoughts and highly original ideas.

 

Re:RTTI, getting procedure names


Quote
Alexander Staubo wrote:

> I have searched the RTTI parts, but I can't find any way to extract
> information about procedures/functions.

> There are functions for converting between enumerated types and strings
> (GetEnumValue, GetEnumName); I need something similar for
> procedures/functions -- simply put, I need a GetProcName function which
> returns a name for a procedure pointer.

> I am aware of the old trick of looking up the procedure address in the MAP
> file. Anybody got some working code which does this? I have no wish to
> "reinvent the wheel" so to speak.

> --
> Alexander Staubo      Professional developer, web designer, purveyor of
> a...@intertele.no     epic thoughts and highly original ideas.

AFAIK, there is no RTTI information stored for normal procedures.
However, Delphi does store the name of all published methods, so
you can get the name of a given method.

I haven't tested this, but you could try something like this:

function GetMethodName(const Method: TMethod): string;
begin
  if Assigned(Method.Data) then
    Result := TObject(Method.Data).MethodName(Method.Code)
  else
    Result := '';
end;

var
  FOnAnyEvent: TNotifyEvent;
  Name : string;
begin
  FOnAnyEvent := MyEventHandler;
  ...
  Name := GetMethodName(FOnAnyEvent);

--
Hallvard Vassbotn
Falcon R&D
Reuters Norge AS

Re:RTTI, getting procedure names


Quote
"Alexander Staubo" <a...@image.no> wrote:
>I have searched the RTTI parts, but I can't find any way to extract
>information about procedures/functions.

>There are functions for converting between enumerated types and strings
>(GetEnumValue, GetEnumName); I need something similar for
>procedures/functions -- simply put, I need a GetProcName function which
>returns a name for a procedure pointer.

>I am aware of the old trick of looking up the procedure address in the MAP
>file. Anybody got some working code which does this? I have no wish to
>"reinvent the wheel" so to speak.

See Ray Lischner's book "Secrets of Delphi 2" - this requires accessing the VMT.
--
Stefan.Hoffmeis...@UNI-Passau.DE
http://kakadu.rz.uni-passau.de/~w4hoff01/
University of Passau, Bavaria, Germany

Other Threads