一般有输入用户名,密码,验证启动主窗体的程序和你说的道理都是一样的。 我的方法是: 在dpr文件中: Application.Initialize; frmpass:=Tfrmpass.Create(application); if frmpass.ShowModal = 1 then begin frmpass.Visible:=false; ........ Application.CreateForm(TMainForm, MainForm); frmpass.Close; Application.Run; end else begin Application.Terminate; exit; end;在frmpass(输入并验证用户名密码的窗体)中放置两个按纽,‘确定'按纽单击事件,self.modalresult:=mrok,在‘取消’中self.modalresult:=mrcancel 就可以了
unit form3;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;type TForm3 = 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; { Public declarations } end;var Form9: TForm9;implementation{$R *.dfm} constructor TForm3.Create(AOwner: TComponent); begin FAsChild := False; inherited Create(AOwner); end;constructor TForm3.Create(AOwner: TComponent; AParent: TWinControl); begin FAsChild := True; FTempParent := aParent; inherited Create(AOwner); end;procedure TForm3.Loaded; begin inherited; if FAsChild then begin align := alClient; BorderStyle := bsNone; BorderIcons := []; Parent := FTempParent; Position := poDefault; end; end;procedure TForm3.CreateParams(var Params: TCreateParams); Begin Inherited CreateParams(Params); if FAsChild then Params.Style := Params.Style or WS_CHILD; end;end;form2 var different:tform3;procedure Tform2.button1Click(Sender: TObject); begin different:=tform3.Create(mainform,panel); different.Show; end;
我的方法是:
在dpr文件中:
Application.Initialize;
frmpass:=Tfrmpass.Create(application);
if frmpass.ShowModal = 1 then begin
frmpass.Visible:=false;
........
Application.CreateForm(TMainForm, MainForm);
frmpass.Close;
Application.Run;
end else begin
Application.Terminate;
exit;
end;在frmpass(输入并验证用户名密码的窗体)中放置两个按纽,‘确定'按纽单击事件,self.modalresult:=mrok,在‘取消’中self.modalresult:=mrcancel
就可以了
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;type
TForm3 = 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;
{ Public declarations }
end;var
Form9: TForm9;implementation{$R *.dfm}
constructor TForm3.Create(AOwner: TComponent);
begin
FAsChild := False;
inherited Create(AOwner);
end;constructor TForm3.Create(AOwner: TComponent; AParent: TWinControl);
begin
FAsChild := True;
FTempParent := aParent;
inherited Create(AOwner);
end;procedure TForm3.Loaded;
begin
inherited;
if FAsChild then
begin
align := alClient;
BorderStyle := bsNone;
BorderIcons := [];
Parent := FTempParent;
Position := poDefault;
end;
end;procedure TForm3.CreateParams(var Params: TCreateParams);
Begin
Inherited CreateParams(Params);
if FAsChild then
Params.Style := Params.Style or WS_CHILD;
end;end;form2
var
different:tform3;procedure Tform2.button1Click(Sender: TObject);
begin
different:=tform3.Create(mainform,panel);
different.Show;
end;