Anyone know if it is possible to know the type of a variable TMethod? example:

Anyone know if it is possible to know the type of a variable TMethod? example:

type
  TMyProc1  = procedure(const Value : string) of object;
  TMyProc2  = procedure(const Value : integer) of object;

Var MT:TMethod;  //Global variable

---Then to set MT variable with some methods
procedure SetMethod1(const AValue:TMyProc1);
begin
  MT := TMethod(AValue);
end;

procedure SetMethod2(const AValue:TMyProc2);
begin
  MT := TMethod(AValue);
end;

Now how can detect wich method type has MT ?
This not work  :P

if MT is TMyProc1  then doSometing1;
if MT is TMyProc2  then doSometing1;

thanks

Comments

  1. It is likely that you are trying to implement something you should not do like that... If you explain your actual problem, then we may suggest a better solution than yours.
    --
    Francois Piette
    Embarcadero MVP

    ReplyDelete
  2. LOL François Piette just hit him with the proverbial wet fish :-P

    ReplyDelete
  3. I'm trying implement very basic Multicast events, looking google, found different approaches, as Im using Delphi7 choose use a TList with TMethod pointers , perhaps there are better solutions, what do you think?

    The basic idea is create a list to store references to several listeners(methods), then at some event (button click, mouse enter, etc) fire the Multicast, execute each method from the list.

    I use a TList to store TMethod pointers, every method has the same parameters so I know how execute them, in fact is working right now

    But I wondered, if I want use different method types with different parameters, I need to know what kind of method is to do the right cast

      TMyProc1(methodList[0]^)('some string parameter');
      
      TMyProc2(methodList[1]^)(0,1); //with 2 int parameters

    ReplyDelete

Post a Comment