如下:SLoginFrom为登陆界面;AMainForm为主界面,在你的工程文件中写一下代码: SLoginFrom:=TSLoginFrom.Create(Application); if SLoginFrom.ShowModal=mrOK then begin Application.CreateForm(TAMainForm, AMainForm); Application.Run; end else Halt; end
begin Application.Initialize; Application.CreateForm(TFrmLogin, FrmLogin); if FrmLogin.ShowModal = mrOK then begin Application.CreateForm(TFrmMain, FrmMain); FrmMain.Show; FrmMain.Update; Application.Run; end; else Showmessage('你不能登陆!'); end.
在主窗体的FormShow事件写代码可实现: ... fmLogin:=TfmLogin.Create(Application); if fmlogin.showmodal<>mrok then Application.Terminate; ...
你可以先写你的main文件,然后新建一个login文件,login文件中设一个全局布尔变量,判断是否登陆成功,然后在工程文件中的uses中添加login,在程序体中添加布尔变量的不同值产生的不同响应.下面是一个实例: program jgwdgf; uses Forms, login, main in 'main.pas' {Form2}, {$R *.res}
begin succeed:=false; //right:=false; form1:=tform1.create(nil); form1.showmodal ; if not succeed then exit else //Application.terminate ; Application.CreateForm(TForm2, Form2); form2.Visible :=true; Application.Run; end. var Form1: TForm1; succeed:boolean; implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);//取消按钮 begin succeed:=false; Close; end;procedure TForm1.Button1Click(Sender: TObject); begin
If (edit1.Text ='') or (edit2.Text ='') then begin If (edit1.Text ='') then begin showmessage('请输入您的帐号!') ;Edit1.SetFocus ;end else If (edit2.Text ='') then begin showmessage('请输入密码!') ;Edit2.SetFocus ;end ; end else begin Query1.Close; Query1.sql.clear; Query1.SQL.Add('select * from operator where name='+#39+edit1.Text+#39 +'and pswd='+#39+edit2.Text+#39); Query1.Open; If (Query1.eof) and (Query1.bof) then begin succeed:=false; close; end else begin succeed:=true; form1.close; end; end;
begin
Application.Initialize;
Application.CreateForm(TFrmMain, FrmMain);
FrmMain.Show;
FrmMain.Update;
Application.CreateForm(TFrmLogin, FrmLogin);
FrmLogin.ShowModal;
FrmLogin.Update;
Application.Run;
end.
在登陆画面中写代码,当登陆不成功时application.Terminate;
SLoginFrom:=TSLoginFrom.Create(Application);
if SLoginFrom.ShowModal=mrOK then
begin
Application.CreateForm(TAMainForm, AMainForm);
Application.Run;
end
else
Halt;
end
begin
Application.initialize;
frmLogin := TFrmLogin.create(self);
Application.createform(TfrmMain, frmMain);
frmLogin.show;
frmLogin.update;
Application.Run;
end;
Application.Initialize;
Application.CreateForm(TFrmLogin, FrmLogin);
if FrmLogin.ShowModal = mrOK then
begin
Application.CreateForm(TFrmMain, FrmMain);
FrmMain.Show;
FrmMain.Update;
Application.Run;
end;
else
Showmessage('你不能登陆!');
end.
...
fmLogin:=TfmLogin.Create(Application);
if fmlogin.showmodal<>mrok then
Application.Terminate;
...
liufh520(天天写程序) 你的程序,仍然出现我原有的问题:没有当前活动的MDI窗口!
bbs791109(小别) 你的程序,出现:[Error] hmga.dpr(23): Undeclared identifier: 'mrok'
program jgwdgf;
uses
Forms,
login,
main in 'main.pas' {Form2},
{$R *.res}
begin
succeed:=false; //right:=false; form1:=tform1.create(nil);
form1.showmodal ; if not succeed then exit else //Application.terminate ; Application.CreateForm(TForm2, Form2);
form2.Visible :=true;
Application.Run;
end.
var
Form1: TForm1;
succeed:boolean;
implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);//取消按钮
begin
succeed:=false;
Close;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
If (edit1.Text ='') or (edit2.Text ='') then
begin
If (edit1.Text ='') then begin showmessage('请输入您的帐号!') ;Edit1.SetFocus ;end else
If (edit2.Text ='') then begin showmessage('请输入密码!') ;Edit2.SetFocus ;end ;
end
else
begin
Query1.Close;
Query1.sql.clear;
Query1.SQL.Add('select * from operator where name='+#39+edit1.Text+#39 +'and pswd='+#39+edit2.Text+#39);
Query1.Open;
If (Query1.eof) and (Query1.bof) then
begin
succeed:=false;
close; end
else
begin
succeed:=true; form1.close; end;
end;