R
redqiao
Unregistered / Unconfirmed
GUEST, unregistred user!
在网络上看了一篇文章,说的是可以动态调用函数或过程,我想问如何实现调用带不同参数的函数,该在哪里写上参数数值?
procedure TForm1.P1(Sender: TObject);
begin
showmessage('In P1 Procedure');
end;
procedure TForm1.P2(Sender: TObject);
begin
showmessage('In P2 Procedure');
end;
procedure TForm1.Button1Click(Sender: TObject);
var m : TMyPorcdure;
s : string;
p : Pointer;
begin
s := 'P1';
p := MethodAddress(s);
if p<>nil then begin
TMethod(m).Code := p;
TMethod(m).Data := Self;
m(Sender);
end
else raise Exception.CreateFmt('Procedure %s not exists',);
s := 'P2';
p := MethodAddress(s);
if p<>nil then begin
TMethod(m).Code := p;
TMethod(m).Data := Self;
m(Sender);
end
else raise Exception.CreateFmt('Procedure %s not exists',);
end;
procedure TForm1.P1(Sender: TObject);
begin
showmessage('In P1 Procedure');
end;
procedure TForm1.P2(Sender: TObject);
begin
showmessage('In P2 Procedure');
end;
procedure TForm1.Button1Click(Sender: TObject);
var m : TMyPorcdure;
s : string;
p : Pointer;
begin
s := 'P1';
p := MethodAddress(s);
if p<>nil then begin
TMethod(m).Code := p;
TMethod(m).Data := Self;
m(Sender);
end
else raise Exception.CreateFmt('Procedure %s not exists',
s := 'P2';
p := MethodAddress(s);
if p<>nil then begin
TMethod(m).Code := p;
TMethod(m).Data := Self;
m(Sender);
end
else raise Exception.CreateFmt('Procedure %s not exists',
end;