unit Unit2;{$mode delphi}{$H+}interfaceuses Classes, SysUtils;type TMyCallback = procedure(S: string);procedure CallIt(const ACallback: TMyCallback);implementationprocedure MyCallback1(S: string);beginend;procedure CallIt(const ACallback: TMyCallback);begin ACallback('Hello');end;end.
procedure MyCallback2(S: string);beginend;procedure TForm1.FormCreate(Sender: TObject);begin CallIt(MyCallback2);end;
I need to use CallIt and pass mycallback2 without using @ pointer of procedure, i don't to lose checking parameters benefits , or using delphi mode in unit1.is there any way to solve it?
{$modeswitch CLASSICPROCVARS}
I need to use CallIt and pass mycallback2 without using @ pointer of procedure, i don't to lose checking parameters benefits , or using delphi mode in unit1.
type TMyCallback = procedure(S: string; ID: Integer);
Also, if you are using the @-address-operator usage of {$typedaddress on} is advised in order to prevent programming mistakes.
unit1.pas(39,22) Error: Incompatible type for arg no. 1: Got "<address of procedure(AnsiString);Register>", expected "<procedure variable type of procedure(AnsiString;LongInt);Register>"