【发布时间】:2014-12-14 08:14:43
【问题描述】:
我有一个从具有 TGlowEffect 的 TImage 派生的组件。我已经安装了它,它在表单上可见。我可以更改发光效果参数,但是当我运行程序时,程序会导致 Rad Studio 崩溃?
这是我的代码。
type
TGlowImage = class( TImage )
private
FGlowEffect: TGlowEffect;
procedure SetGlowEffect( const Value : TGlowEffect );
protected
public
constructor Create( AOwner : TComponent); override;
destructor Destroy(); override;
published
property GlowEffect : TGlowEffect read FGlowEffect write SetGlowEffect;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents( 'SomeCompany', [TGlowImage] );
end;
{ TGlowImage }
constructor TGlowImage.Create( AOwner : TComponent );
begin
inherited;
FGlowEffect := TGlowEffect.Create( Self )
end;
destructor TGlowImage.Destroy();
begin
if( Assigned( FGlowEffect ) ) then
FreeAndNil( FGlowEffect );
inherited;
end;
procedure TGlowImage.SetGlowEffect( const Value : TGlowEffect );
begin
FGlowEffect.Assign( Value );
end;
我不知道我错过了什么,但一定很糟糕。
任何帮助将不胜感激。
【问题讨论】:
-
“程序崩溃 RAD Studio”不是一个有用的问题描述。您收到错误消息吗?如果是这样,它说明了什么?在测试之前不要安装组件。为此,您可以在测试应用程序的代码中创建它,并将参数设置为不同的值;如果它不起作用,您可以轻松地使用调试器来确定原因。彻底测试后,然后安装它。
-
不是崩溃的原因,但在你的析构函数中没有必要在 FreeAndNil 之前调用 Assigned。可以使用 nil 引用安全地调用 FreeAndNil。
标签: delphi