Saving a pointer to a specified function in Delphi

Not sure if the type is correct, but what I need to do is to store a pointer to the specified function in some collection. I do it very much like declaring a variable

SomeFunctionName: string

Of course, this type cannot be a string, the question is what exactly should be?

+5
source share
2 answers

Usually you use a function pointer variable. For instance:

type
  TProcedure = procedure;

procedure MyProc1;
begin
end;

procedure MyProc2;
begin
end;

var
  Proc: TProcedure;

.....
Proc := MyProc1;
Proc();//calls MyProc1
Proc := MyProc2;
Proc();//calls MyProc2

This is the simplest example. You can specify procedural types containing a list of parameters, an object type method, etc. For more information, see Procedural Types in the Language Guide.

+6
source

In fact, you do not store the procedure / function, but you save the method.

, TMethod . TMethod .

:

edit: , - TControl.onClick.....

+1

All Articles