我有个过程procedure Tzmenu_w.zmenu_cxm_prog;
begin
if a1='cggl' then
P1 else
if a1='xsgl' then
P2 else
if a1='kcgl' then
P3 else
...............end;
说明:p1,p2,p3....都是过程名,也许以上的过程有几百行代码,我想用一个选择判断语句搞定
那么这样就需要用变量名代替过程名
procedure Tzmenu_w.zmenu_cxm_prog;
begin
if 条件 成立 就执行 某变量(其实这变量与某过程关联)
begin
if a1='cggl' then
P1 else
if a1='xsgl' then
P2 else
if a1='kcgl' then
P3 else
...............end;
说明:p1,p2,p3....都是过程名,也许以上的过程有几百行代码,我想用一个选择判断语句搞定
那么这样就需要用变量名代替过程名
procedure Tzmenu_w.zmenu_cxm_prog;
begin
if 条件 成立 就执行 某变量(其实这变量与某过程关联)
begin
showmessage('abc')
end;procedure TForm1.Button1Click(Sender: TObject);
var
p1: procedure of object;
begin
p1 := proc;
p1;
end;
TStrProc=Procedure(const S :string);var
MyStrProc :TStrProc;
//假如有一个过程 Procedure Test(const S:string);
//另一个过程Procedure Test2(const S:string);
MyStrProc := Test; //
MyStrProc(S); //执行Test;
MyStrProc := Test2;
MyStrProc(S);//执行Test2;
比如:
type
TOperatorType=(EVENT_P1,EVENT_P2,...);
function MakeSqlStr_CallProcDoSmth(nEvent:TOperatorType):string;
var strSql:string;
begin
case nEvent of
event_p1:strsql:=format('',[]);
event_p2:strsql:=format('',[]);
default:string='';
end;
result:=strsql;
end;
type
TCalls = class
published
procedure a1;
procedure a2;
end; TCall = procedure;{ TCalls }procedure TCalls.a1;
begin
ShowMessage('a1');
end;procedure TCalls.a2;
begin
ShowMessage('a2');
end;
注意方法要放publishedfunction Call(const name: string): Boolean;
var
p: Pointer;
begin
p := TCalls.MethodAddress(name);
Result := p <> nil;
if Result then
TCall(p);
end;调用直接传入函数名就可以Call('a1');
Call('a2');