Hi,
here is a simple Callback... Hope you understand a bit more...
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
StdCtrls;
//Simple Callback passing to a variable
// for this example just place a button and progressbar on the form
type
// Callback function to be invoked by any outer function/procedure
TMyCallbackProc = procedure(const APos, AMax: Integer) of object; stdcall; // functions as well
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);
private
procedure MyCallBack(const APos, AMax: Integer); stdcall;
procedure CallReference(ACallback: TMyCallbackProc);
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
CallReference(@MyCallBack);
end;
procedure TForm1.MyCallBack(const APos, AMax: Integer); stdcall;
begin
// here you can handle single items
// e.g. if you iterate (e.g. for-loop) items or sth...
// i just update the progressbar
// if this proc was a function
// you could add conditions to
// tell the outer function e.g.
// to stop or go on (or what ever)
ProgressBar1.Position:=APos;
ProgressBar1.Max:=AMax;
end;
procedure TForm1.CallReference(ACallback: TMyCallbackProc);
var
i: integer;
iMax: Integer;
begin
if assigned(ACallback) then
begin
// CallReference does not care
// about what ACallback can do :)
// you can define more
// MyCallBack-similar function
// and pass them how you like...
iMax := 10;
for i := 0 to iMax-1 do
begin
ACallback(i+1,iMax);
sleep(500); // just to show, the progressbar steps up
end;
end;
end;
end.
Cheers,
yorako1