views:

70

answers:

1

Hello. I have a class (TExample) and I want to have an array of pointers that point to TExample methods. For example, I'd like to have TExample.ThinkOne and do aPointers[1] := @TExample.ThinkOne or something similar. How can I properly do this? Thanks.

+1  A: 

You can do something like this:

type
  TProcType = procedure(const AParm: Integer) of object; // Method type
  TProcArray = array of TProcType; // Dynamic array 
  TExample = class
  public
    procedure A(const AParm: Integer); // Method signature matches TProcType
    procedure B(const AParm: Integer);
  end;

var
  pa : TProcArray;

procedure Init(const AExample: TExample);
begin
  SetLength(pa, 2);
  pa[0] := AExample.A;
  pa[1] := AExample.B;
end;      
Gamecat