Question

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.

Was it helpful?

Solution

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;      
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top