A: A call back function is a function which you write, but is
called by some other program or module, such as windows. To
create a callback function, you must first declare a function type, the
funciton itself, and implement
the function. In the interface section:
{ In main program interface }
type
TCallBackFunction = function(s: string): integer;
CallMe(s: string): integer;
And in the Implementation section:
{ In main program implementation }
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 to do }
CallMe := 1; { What ever you need to return }
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
TestCallBack(CallMe);
end;
Note that in 'Other' you would also declare a function type, and use
it
like this:
{ in library Other interface }
type
TMainFunction = function(s: string): integer;
TestCallBack(MainFunc: TMainFunction);
{ in library Other implementation }
TestCallBack(MainFunc: TMainFunction);
var
result: integer;
begin
result:=MainFunc('test');
end;