假设有一个对象有一个类如何:
Tx1Control=class(TComponent)
public
procedure Action1(S:String); // 所有ACTION参数形式一样
procedure Action2(S:String);
.....//更多的action
end;
Tx2Control=class(TComponent)
public
procedure Action1(S:String); // 所有ACTION参数形式一样
procedure Action2(S:String);
.....//更多的action
end;
现有一个函数,根据输入的类名和Action名字就能动态调用该类的方法
如:
procedure Run(AClass:TClass:A:String;S:String);
var
obj:TComponent;
begin
obj:=AClass.Create;
if A='Action1' then obj.Action1(S)
else A='Action2' then obj.Action2(S);
//还有很多的Action.....
end;
显然,RUN中这种方法太死了,对于还有很多action来说,是不行的。
有没有更灵活的方法呢?