how do I get Run Time info from a published method?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

how do I get Run Time info from a published method?

Dennis Poon
say for example:

   type
      TmyClass = class
      published
         procedure Something (sender : Tobject);virtual;
     end;

var
   myClass  : TmyClass;

then somewhere

     AddMethodToQueue(@myclass.Something);


Is it possible within AddMethodToQueue, I can query the Run Time Type
Info of the method passed in ?



procedure AddMethodToQueue(const TheEvent : TNotifyEvent);
var aMethodObjectname : String;
begin
     //I can already do this
      aMethodObjectName := TObject(TMethod(TheEvent).Data).ToString;

     //how do I check the RTTI of TheEvent and get the name of the
method i.e. 'Something'?
    //since it is published, it should be possible, right?

end;

Thanks in advance.

Dennis
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: how do I get Run Time info from a published method?

etrusco
On Mon, Sep 29, 2014 at 11:54 PM, Dennis Poon <[hidden email]> wrote:

> say for example:
>
>   type
>      TmyClass = class
>      published
>         procedure Something (sender : Tobject);virtual;
>     end;
>
> var
>   myClass  : TmyClass;
>
> then somewhere
>
>     AddMethodToQueue(@myclass.Something);
>
>
> Is it possible within AddMethodToQueue, I can query the Run Time Type Info
> of the method passed in ?
>
>
>
> procedure AddMethodToQueue(const TheEvent : TNotifyEvent);
> var aMethodObjectname : String;
> begin
>     //I can already do this
>      aMethodObjectName := TObject(TMethod(TheEvent).Data).ToString;
>
>     //how do I check the RTTI of TheEvent and get the name of the method
> i.e. 'Something'?
>    //since it is published, it should be possible, right?
>
> end;
>
> Thanks in advance.
>
> Dennis
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Simply:

  vObj := TObject(TMethod(TheEvent).Data);
  vMethodName := vObj.MethodName(TMethod(TheEvent).Code);

?

Regards,
Flávio
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: how do I get Run Time info from a published method?

Dennis Poon
Flávio


Thanks so much.

Dennis


_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal