一,普通的函数和过程的声明和调用;
procedure myProc(sFileName:string); begin deletefile(sFileName); end; function myFunc(sFileName:string):boolean; begin result := deletefile(sTemp); ed;
二,函数,过程型变量;
var p : procedure (sFileName:string); //注意没有过程名称 procedure myProc(sFileName:string); begin deletefile(sFileName); end; p := myProc; p(sFileName); var f : function (sFileName:string):boolean; function myFunc(sFileName:string):boolean; begin result := deletefile(sTemp); ed; f := myFunc; F(sFileName);
三,自定义函数或过程类型;
type myPtr = procedure (sFileName : string);
procedure MyDeleteFileProc(sFileName : string);
begin
deletefile(sFileName);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ptr : myPtr;
begin
ptr := MyDeleteFileProc;
ptr( 'D:\delphi_pas\test\1.exe' );
end;