参考DELPHI帮助文档:Loaded method (TCustomForm) Performs fix-ups when the form is first loaded into memory.Delphi syntax:procedure Loaded; override;C++ syntax:virtual void __fastcall Loaded(void);DescriptionLoaded overrides the inherited method to give focus to the ActiveControl if it is assigned. Before assigning focus, Loaded calls the inherited method to perform any lower-level initialization.就是说在窗体第一次装载到内存中,会调用这个方法,你可以重载它。 --------------------------------------------------- 以下转自 http://www.ddvip.net/program/delphi/index1/73.htm 在部件从存储的描述中读取所有的属性后,它调用名为Loaded的虚方法,这提供了按需要执行任何初始化的机会。调用Loaded是在窗体和它的控制显示之前,因此,不需要担心初始化会带来屏幕闪烁。 在部件载入属性时初始化它,要覆盖Loaded方法。 在Loaded方法中,要做的第一件事是调用继承的Loaded方法。这使得在你的部件执行初始化之前,任何继承的属性都已初始化。----------------------------------------------------------- 以下例子代码来源于 GamePaladin II(源代码公开的游戏修改器) TChildForm = class(TTntForm) private FAsChild: Boolean; FTempParent: TWinControl; protected procedure CreateParams(var Params: TCreateParams); override; procedure Loaded; override; public constructor Create(AOwner: TComponent; AParent: TWinControl); reintroduce; overload; // The method below must be overridden to return either the main menu // of the form, or nil. function GetFormMenu: TMainMenu; virtual; abstract; function CanChange: Boolean; virtual; end; constructor TChildForm.Create(AOwner: TComponent; AParent: TWinControl); begin FAsChild := True; FTempParent := aParent; inherited Create(AOwner); end;procedure TChildForm.Loaded; begin inherited; if FAsChild then begin Align := alClient; BorderStyle := bsNone; BorderIcons := []; Parent := FTempParent; Position := poDefault; end; end;procedure TChildForm.CreateParams(var Params: TCreateParams); Begin Inherited CreateParams(Params); if FAsChild then Params.Style := Params.Style or WS_CHILD; end; function TChildForm.CanChange: Boolean; begin Result := True; end;
Performs fix-ups when the form is first loaded into memory.Delphi syntax:procedure Loaded; override;C++ syntax:virtual void __fastcall Loaded(void);DescriptionLoaded overrides the inherited method to give focus to the ActiveControl if it is assigned. Before assigning focus, Loaded calls the inherited method to perform any lower-level initialization.就是说在窗体第一次装载到内存中,会调用这个方法,你可以重载它。
---------------------------------------------------
以下转自 http://www.ddvip.net/program/delphi/index1/73.htm
在部件从存储的描述中读取所有的属性后,它调用名为Loaded的虚方法,这提供了按需要执行任何初始化的机会。调用Loaded是在窗体和它的控制显示之前,因此,不需要担心初始化会带来屏幕闪烁。 在部件载入属性时初始化它,要覆盖Loaded方法。 在Loaded方法中,要做的第一件事是调用继承的Loaded方法。这使得在你的部件执行初始化之前,任何继承的属性都已初始化。-----------------------------------------------------------
以下例子代码来源于 GamePaladin II(源代码公开的游戏修改器)
TChildForm = class(TTntForm)
private
FAsChild: Boolean;
FTempParent: TWinControl;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure Loaded; override;
public
constructor Create(AOwner: TComponent; AParent: TWinControl); reintroduce; overload;
// The method below must be overridden to return either the main menu
// of the form, or nil.
function GetFormMenu: TMainMenu; virtual; abstract;
function CanChange: Boolean; virtual;
end;
constructor TChildForm.Create(AOwner: TComponent; AParent: TWinControl);
begin
FAsChild := True;
FTempParent := aParent;
inherited Create(AOwner);
end;procedure TChildForm.Loaded;
begin
inherited;
if FAsChild then
begin
Align := alClient;
BorderStyle := bsNone;
BorderIcons := [];
Parent := FTempParent;
Position := poDefault;
end;
end;procedure TChildForm.CreateParams(var Params: TCreateParams);
Begin
Inherited CreateParams(Params);
if FAsChild then
Params.Style := Params.Style or WS_CHILD;
end;
function TChildForm.CanChange: Boolean;
begin
Result := True;
end;