I have the following method pointers
TMethod1 = procedure(aValue: TType1) of object;
TMethod2 = procedure(aValue: TType2) of object;
TMethodN = procedure(aValue: TTypeN) of object;
I want to store them in one container.
I found this answer, where a pointer to
TMethod1 is used to store one method and then call it. However, I would rather not use it for the following reasons:
It allocates new block of memory and then later I should decide when to free it(never made it out of that area in one piece).
It assumes all methods have the same definition, which is not my case.
It is for one method. I have an array of them, and I do not see how I'm going to maintain such storage.
And there is an example in the documentation which uses a
TMethod approach, but in a different way where the second assumption above is no longer needed. In the last step to call the method, I have to do an unsafe typecast, which again is something I would like to stay away from.
How do I accomplish this?
Clarification on how I'm going to use these methods:
I have a
procedure DoWork(aData: TType1; method: TMethod1);
store aData in a field;
store method in my container;
Then later, process
aData and call