Shape_class=class(tobject)
Constructor create;
Destructor Demolish;
Public
Shape:tshape;
Shape_width,
Shape_height,
Shape_left,
Shape_top:integer;
End;
Function add_shape
:Shape_class;
Begin
Result:=shape_class.create;
End;
代码已经简化,但说明了我的代码中发生了什么。调试器忽略对构造函数的调用。如果我将指针悬停在调用中的class_name标识符上,则提示通知我'链接符消除了符号'。
我不知道造成这种情况的原因。我想知道它是否与堆栈的大小有关,但增加堆栈没有任何区别。
答案 0 :(得分:3)
这是一个自我毁灭性的答案(因为它只是一个长篇评论)
没有SSCCE
,您的问题无法解答到目前为止,我构建了一个小型控制台应用程序来测试您的代码
program so_21982168;
{$APPTYPE CONSOLE}
{$R *.res}
uses
SysUtils;
type
Shape_class = class( tobject )
Constructor create;
Destructor Demolish;
Public
Shape : tobject;
Shape_width, Shape_height, Shape_left, Shape_top : integer;
End;
Function add_shape : Shape_class;
Begin
Result := Shape_class.create;
End;
{ Shape_class }
Constructor Shape_class.create;
Begin
Writeln( 'shape_class.create called' );
Shape := tobject.create;
End;
Destructor Shape_class.Demolish;
Begin
Writeln( 'shape_class.Demolish called' );
Shape.Free;
End;
procedure Test;
var
LInstance : Shape_class;
Begin
Writeln( 'Test ENTER' );
LInstance := Shape_class.create;
try
Assert( Assigned( LInstance ) );
finally
LInstance.Free;
End;
Writeln( 'Test LEAVE' );
End;
Begin
try
Test;
except
on E : Exception do
Writeln( E.ClassName, ': ', E.Message );
End;
Readln;
End.
输出
Test ENTER shape_class.create called Test LEAVE
destructor Demolish
Free
Shape
实例将不被释放)