J
jshyhzj
Unregistered / Unconfirmed
GUEST, unregistred user!
//程序中有一行,加不加此行,运行结果不同!
//您能清晰地解释此现象的原因么?
//这是我特意构造的陷阱
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFun = function: string of object;
TTest = class
public
function getName: string;
procedure testProc;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
procedure test(AFun: TFun);
implementation
{$R *.dfm}
procedure test(AFun: TFun);
begin
showmessage(AFun);
end;
{ TTest }
function TTest.getName: string;
begin
result := self.ClassName;
end;
procedure TTest.testProc;
begin
test(getName);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
t: TTest;
begin
t:= TTest.Create
//加不加此行,运行结果不同!
t.testProc;
end;
end.
//您能清晰地解释此现象的原因么?
//这是我特意构造的陷阱
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TFun = function: string of object;
TTest = class
public
function getName: string;
procedure testProc;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
end;
var
Form1: TForm1;
procedure test(AFun: TFun);
implementation
{$R *.dfm}
procedure test(AFun: TFun);
begin
showmessage(AFun);
end;
{ TTest }
function TTest.getName: string;
begin
result := self.ClassName;
end;
procedure TTest.testProc;
begin
test(getName);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
t: TTest;
begin
t:= TTest.Create
//加不加此行,运行结果不同!
t.testProc;
end;
end.