比如我一个类中有一个方法function abc():string;现在我想从外部TXT中读一个字串变量,通过这个变量来得到abc这个方法.
不要用if 字串=abc then
do abc方法因为我N多方法名,如果取回某个字串都得IF一下,哪我要写上千行IF代码..
不要用if 字串=abc then
do abc方法因为我N多方法名,如果取回某个字串都得IF一下,哪我要写上千行IF代码..
解决方案 »
- 怎么把一个字符串数组付值给ListView?
- delphi + sql2k怎么防止同时对一个表的同一记录 更新
- delphi7 Edit中内容显示内容变为 * 我找不到Edit的 passwordchar属性
- 高分求教组件开发的问题!
- 如何直接用tsocket实现HTTP协议提交数据?
- 關于對adoqeuery的參數及值保存再還原的問題。請高手幫忙
- 请问:pascal 中如何定义类型
- 高薪聘请delphi界面工程师
- 十万火急:我从新安装了WIn98,再安装Delphi5.5。我关闭点击RUN运行的程序,出现异常情况
- 各位大虾:如何给程序和动态库减肥
- 如何用HOOK来监视任何对文件的单击事件?
- TObject和String的转换问题
如果是用IF 字串=abc then这样允余的代码,哪太费时了.有没有什么方法,可以FindMethod('字串')返回的是一个函数指针....
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations } public
{ Public declarations }
published
procedure SayHello();
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.SayHello;
begin
ShowMessage('Hello Word!');
end;procedure TForm1.btn1Click(Sender: TObject);
var
AMethod:TMethod;
Proc:Procedure of object;
begin
AMethod.Code:=self.MethodAddress('SayHello');
AMethod.Data:=self;
TMethod(Proc):=AMethod;
Proc;
end;
end.
a:Pointer;
s:string;
begin
s:='abc';
a:=MethodAddress(s); //根据方法名获取其地址
CallWindowProc(a,Handle,0,0,0);//执行方法不过方法必须要在pushlished下