P
poorness
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
AFunctionType = function(IntIn : integer) : integer;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function AddProc(IntIn : integer) : integer;
function SubProc(IntIn : integer) : integer;
procedure PassAFunction(var IntIn : integer;
fn : AFunctionType);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.AddProc(IntIn : integer) : integer;
begin
Result := IntIn + 1;
end;
function TForm1.SubProc(IntIn : integer) : integer;
begin
Result := IntIn - 2;
end;
procedure TForm1.PassAFunction(var IntIn : integer;
fn : AFunctionType);
begin
IntIn := fn(IntIn);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin
i := 10;
PassAFunction(i, @AddProc);
ShowMessage(IntToStr(i));
PassAFunction(i, @SubProc);
ShowMessage(IntToStr(i));
end;
运行提示:
在 PassAFunction(i, @AddProc);
variabled required
请问高手如何解决
end.
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
AFunctionType = function(IntIn : integer) : integer;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function AddProc(IntIn : integer) : integer;
function SubProc(IntIn : integer) : integer;
procedure PassAFunction(var IntIn : integer;
fn : AFunctionType);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
function TForm1.AddProc(IntIn : integer) : integer;
begin
Result := IntIn + 1;
end;
function TForm1.SubProc(IntIn : integer) : integer;
begin
Result := IntIn - 2;
end;
procedure TForm1.PassAFunction(var IntIn : integer;
fn : AFunctionType);
begin
IntIn := fn(IntIn);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i : integer;
begin
i := 10;
PassAFunction(i, @AddProc);
ShowMessage(IntToStr(i));
PassAFunction(i, @SubProc);
ShowMessage(IntToStr(i));
end;
运行提示:
在 PassAFunction(i, @AddProc);
variabled required
请问高手如何解决
end.