介绍一种简单利用字符串来调用函数的方法 from 苦瓜
qi_gu 2003-02-23 01:18:08 unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
published
{ Public declarations }//必须放到published中,
procedure ShowIt;
Procedure ShowIt1;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ShowIt;
begin
ShowMessage('ShowIt');
end;
procedure TForm1.ShowIt1;
begin
ShowMessage('ShowIt1');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
CallMethod : Pointer;
begin
CallMethod := MethodAddress('ShowIt1');//此处可以换成ShowIt,试验.
If CallMethod <> nil then
Asm
CALL CallMethod
end;
end;
end.//这是利用了Delphi 方法指针,和Delphi的内部流机制,希望对大家有所帮助.