Not sure if the tittle is right but what I need to do is to store in some collection a pointer to specified function. I'm doing that pretty much like declaring a variable
SomeFunctionName: string
Of course this type can't be a string, the question is what should it exactly be?
You would typically use a function pointer variable. For example:
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 most simple example imaginable. You can specify procedural types that have parameter list, method of object types and so on. Read more in the Procedural Types topic of the language guide.
You are actually not storing procedure / function but storing method.
So you should use TMethod Instead. A TMethod has a object pointer and a procedure pointer.
You can see more detail in another post : Save and restore event handlers
edit : It seems the question has been edit back to original after showing some Storing TControl.onClick event request.....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With