源程序如下
unit ChildFrm;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ExtCtrls, Menus;type TChildForm = class(TForm)
private
FAsChild: Boolean;
FTempParent: TWinControl;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure Loaded; override;
public
constructor Create(AOwner: TComponent); overload; override;
constructor Create(AOwner: TComponent; AParent: TWinControl); reintroduce; overload;
function GetFormMenu: TMainMenu; virtual; abstract;
function CanChange: Boolean; virtual;
end;var
ChildForm: TChildForm;implementation{$R *.DFM}
constructor TChildForm.Create(AOwner: TComponent);
begin
FAsChild := False;
inherited Create(AOwner);
end;constructor TChildForm.Create(AOwner: TComponent; AParent: TWinControl);
begin
FAsChild := True;
FTempParent := aParent;
inherited Create(AOwner);//如果将inherited Create(AOwner)放到前面效果和Create一样
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;end.请高手帮帮忙
告诉我为什么会这样
unit ChildFrm;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, ExtCtrls, Menus;type TChildForm = class(TForm)
private
FAsChild: Boolean;
FTempParent: TWinControl;
protected
procedure CreateParams(var Params: TCreateParams); override;
procedure Loaded; override;
public
constructor Create(AOwner: TComponent); overload; override;
constructor Create(AOwner: TComponent; AParent: TWinControl); reintroduce; overload;
function GetFormMenu: TMainMenu; virtual; abstract;
function CanChange: Boolean; virtual;
end;var
ChildForm: TChildForm;implementation{$R *.DFM}
constructor TChildForm.Create(AOwner: TComponent);
begin
FAsChild := False;
inherited Create(AOwner);
end;constructor TChildForm.Create(AOwner: TComponent; AParent: TWinControl);
begin
FAsChild := True;
FTempParent := aParent;
inherited Create(AOwner);//如果将inherited Create(AOwner)放到前面效果和Create一样
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;end.请高手帮帮忙
告诉我为什么会这样
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货