Calling functions/procedures runtime
Posted on 1998-12-28
OK, this is a bit complicated...
I am not going to explain exactly why I need this but rather what I need.
I have a function in one of my unit files which is publicly accessable:
function MYFUNC(param1, param2, param3: String): String;
In the "old" days when I still programmed in Clipper I would have been able to do the following:
//I set x equal to a string as follows
x = "MYFUNC('String1','String2','String3')"
//Now I can "execute" x.
SavedVal := &X
What the above would do is run MYFUNC('String1','String2','String3') saving the result into SavedVal.
This is exactly what I need to do in Delphi.
I have the function name as a string as well as the three parameters for this function. I concatenate these to build up the function call with it's parameter giving me:
TheString := 'MYFUNC(''String1'',''String2'',''String3'')'
Is there a way to have Delphi evaluate TheString at runtime returning the result from the function?
NewString := IWouldLikeToRunThis(TheString);
Using case statement and IF clauses is what I'm trying to avoid. In other word I don't need anything that looks like the code below as an answer.
IF FunctionName = 'MYFUNC' then MyFunc(Param1,Param2,Param3)
ELSE IF FunctionName = 'ANOTHERFUNC then AnotherFunc(Param1)
Thank you in advance