相关疑难解决方法(0)

如何在Delphi中模拟TFrame上的OnDestroy事件?

我怎样才能在Delphi中模拟一个OnDestroy事件TFrame


我简单地添加了一个constructordestructor我的框架,认为这是做什么的TForm:

TframeEditCustomer = class(TFrame)
...
public
   constructor Create(AOwner: TComponent); override;
   destructor Destroy; override;
   ...
end;

constructor TframeEditCustomer.Create(AOwner: TComponent)
begin
    inherited Create(AOwner);

    //allocate stuff
end;

destructor TframeEditCustomer.Destroy;
begin
   //cleanup stuff

   inherited Destroy;
end;
Run Code Online (Sandbox Code Playgroud)

这个问题是,当我的析构函数运行时,框架上的控件已经被破坏并且不再有效.

原因在于包含表单的析构函数,它用于触发OnDestroy事件:

destructor TCustomForm.Destroy;
begin
   ...
   if OldCreateOrder then DoDestroy; //-->fires Form's OnDestroy event; while controls are still valid
   ...
   if HandleAllocated then DestroyWindowHandle; //-->destroys all controls on the form, and child frames
   ...
   inherited …
Run Code Online (Sandbox Code Playgroud)

delphi destructor delphi-5 tframe

6
推荐指数
1
解决办法
6276
查看次数

标签 统计

delphi ×1

delphi-5 ×1

destructor ×1

tframe ×1