Hi,
Is there any way to do this in FreePascal like Delphi( and I don't want to use prefix @)?
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
TCalcFunction = function(V1,V2:integer):integer;
var
Form1: TForm1;
implementation
{$R *.lfm}
function SumFunction(V1,V2:integer):integer;
begin
Result:=V1+V2;
end;
function Calculator(CalcFunction:TCalcFunction;V1,V2:integer):integer;
begin
CalcFunction(V1,V2);
end;
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(IntToStr(Calculator(@SumFunction,2,3)));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ShowMessage(IntToStr(Calculator(
function SumFunction(V1,V2:integer):integer
begin
Result:=V1+V2;
end
,1,2)));
end;
end.