S
sileo
Unregistered / Unconfirmed
GUEST, unregistred user!
怎样用函数名为参数, 在调用函数中调用"函数入口"为名的函数?
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function pro1:string;
function pro2:string;
procedure dopro(sname:string);
var
Form1: TForm1;
implementation
{$R *.DFM}
function pro1:string;
begin
...
Result := 'pro1';
end;
function pro2:string;
begin
...
Result := 'pro2';
end;
procedure dopro(sname:xxxxxx)
//我想传function proc1 或function proc2
var
s: string;
begin
...
showmessage('begin');
//前面是pro1 和 pro2都通用的部分.
s := sname
//怎么调用function pro1/pro2
showmessage(s);
//后面是pro1 和 pro2都通用的部分.
...
showmessage('end');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
dopro('pro1')
//想调用dopro 并在dopro调用pro1
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
dopro('pro2')
//想调用dopro 并在dopro调用pro2
end;
...
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function pro1:string;
function pro2:string;
procedure dopro(sname:string);
var
Form1: TForm1;
implementation
{$R *.DFM}
function pro1:string;
begin
...
Result := 'pro1';
end;
function pro2:string;
begin
...
Result := 'pro2';
end;
procedure dopro(sname:xxxxxx)
//我想传function proc1 或function proc2
var
s: string;
begin
...
showmessage('begin');
//前面是pro1 和 pro2都通用的部分.
s := sname
//怎么调用function pro1/pro2
showmessage(s);
//后面是pro1 和 pro2都通用的部分.
...
showmessage('end');
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
dopro('pro1')
//想调用dopro 并在dopro调用pro1
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
dopro('pro2')
//想调用dopro 并在dopro调用pro2
end;
...