I am attempting to reference a procedure as a parameter of another procedure and am having trouble understanding the documentation.(http://docwiki.embarcadero.com/RADStudio/Sydney/en/Procedural_Types_(Delphi))
From what I understood I need to create a new type for the procedure..
type
TCallback = procedure of object;
and declare the higher order procedure as
procedure HigherOrder(pProc: TCallback);
I receive the compilation error " E2010 Incompatible types: 'TCallBack' and 'procedure, untyped pointer or untyped parameter' " when attempting to call the function(when the button is clicked)
type
TCallBack = procedure of object;
TfrmMain = class(TForm)
btnAct: TButton;
procedure btnActClick(Sender: TObject);
private
procedure HigherOrder(pProc: TCallback);
procedure Callback();
{ Private declarations }
public
{ Public declarations }
end;
var
frmMain: TfrmMain;
implementation
{$R *.dfm}
{ TfrmMain }
procedure TfrmMain.btnActClick(Sender: TObject);
begin
HigherOrder(Callback()); <--Error occurs here
end;
procedure TfrmMain.Callback;
begin
//Do some stuff
end;
procedure TfrmMain.HigherOrder(pProc: TCallback);
begin
//Do some other stuff
pProc();
end;
end.
Any help is greatly appreciated. I am quite new to programming in delphi.