Talk:callback

From Lazarus wiki
Jump to navigationJump to search

Does that really constitute a callback?
This, I would call a callback:

type
  TProgressProc = procedure(const APercentage: Double);
...
procedure ShowProgress(const APercentage: Double);
begin
  //code to show e.g. a progress bar
end;

procedure CopyFile(const Sr, Dst: String; AProgressProc: TProgressProc);
begin
  ...
  //while copying blocks of data then call
  AProgressProc(CalculatedPercentage);
  ...
end;

...
begin
  CopyFile('MyOrig.pas', 'MyBackup.pas', @ShowProgress);
end.

--Bart (talk) 16:00, 17 November 2020 (CET)