문제

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.

도움이 되었습니까?

해결책

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;      
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top