问题描述
我已经将 TFrame
的后代类注册为组件,并且我注意到 Loaded
过程执行了两次:
I've registered as component a TFrame
's descendant class and I've noticed that the Loaded
procedure is executed twice:
运行时:
TMyFrame = class(TFrame)
private
protected
procedure Loaded(); override;
public
constructor Create(AOwner : TComponent); override;
end;
constructor TMyFrame.Create(AOwner : TComponent);
begin
ShowMessage('Before TMyFrame.Create');
inherited Create(AOwner);
ShowMessage('After TMyFrame.Create');
end;
procedure TMyFrame.Loaded();
begin
ShowMessage('Before TMyFrame.Loaded');
inherited;
ShowMessage('After TMyFrame.Loaded');
end;
设计时间:
procedure Register;
begin
RegisterComponents('Test', [TMyFrame]);
end;
输出:
在运行时,创建包含 TMyFrame
组件的表单时.
At runtime, on creating a form in which there is a TMyFrame
component.
在TMyFrame.Loaded之前
Before TMyFrame.Loaded
TMyFrame.Loaded之后
After TMyFrame.Loaded
在TMyFrame.Create之后
After TMyFrame.Create
在TMyFrame.Loaded之前
Before TMyFrame.Loaded
TMyFrame.Loaded之后
After TMyFrame.Loaded
在设计时,将 TMyFrame
添加到表单中:
At designtime, on adding a TMyFrame
to a form:
在TMyFrame.Loaded之前
Before TMyFrame.Loaded
TMyFrame.Loaded之后
After TMyFrame.Loaded
在TMyFrame.Create之后
After TMyFrame.Create
在设计时,打开一个包含 TMyFrame
组件的表单:
At designtime, opening a form in which there is a TMyFrame
component:
在TMyFrame.Loaded之前
Before TMyFrame.Loaded
TMyFrame.Loaded之后
After TMyFrame.Loaded
在TMyFrame.Create之后
After TMyFrame.Create
在TMyFrame.Loaded之前
Before TMyFrame.Loaded
TMyFrame.Loaded之后
After TMyFrame.Loaded
为什么 Loaded
过程执行两次?如何避免这种情况?
Why the Loaded
procedure is executed twice? How to avoid this?
推荐答案
此行为是设计的.
这篇关于为TFrame的后代执行了两次加载程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!