Delphi中定义回调函数
type
TCallBackFunction = function(s: string): integer;
CallMe(s: string): integer;
procedure TestCallBack(CallBackFunction: TCallBackFunction);
far;
external 'Other';
{ Note that 'other' is a Dll containing the procedure TestCallBack }
function CallMe(s: PChar): integer;
begin
{ what ever you need todo
}
CallMe := 1;
{ What ever you need to return }
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TestCallBack(CallMe);
end;
type
TMainFunction = function(s: string): integer;
TestCallBack(MainFunc: TMainFunction);
{ in library Other implementation }
TestCallBack(MainFunc: TMainFunction);
var
result: integer;
begin
result:=MainFunc('test');
end;