Home > Back-end >  Novice window display problem, ask for help!
Novice window display problem, ask for help!

Time:09-27

A login form, a MDI main form, set the MDI main form is given priority to the form, and then in the main form of SHOW events
Procedure Tfrm_main. FormShow (Sender: TObject);
The begin
Frm_login. ShowModal;
Statusbar1. Panels [1]. The Text:='operator: [' + user_id +'] '.
end;
Show the login form first, determine the login form button code:
Procedure Tfrm_login. BitBtn1Click (Sender: TObject);
Var SQLSTR: string;
The begin
SQLSTR:='select * from the users where id=' "+ edit1. Text + ' ' 'and PWD='" + edit2. Text + "'" ';
Adoquery1. Close;
Adoquery1. SQL. The Clear;
Adoquery1. SQL. The Add (SQLSTR);
Adoquery1. Open;
If adoquery1. RecordCount & lt;> 0 then
The begin
User_id:=edit1. Text;
Frm_main. Show;
Frm_login. Close;
End the else
The begin
Showmessage (' user name or password mistake, please input again, ');
Edit1. The clear;
Edit2. The clear;
Edit1. SetFocus;


end;




end;
Found a problem the password input error, the execution to showmessage that step, the login window displays a dialog box "user name or password mistake, please input again," after enter directly shows that the main form, under the guidance of which player can not, wrong password should get focus and continued to perform user name,

CodePudding user response:

1, we should set the login window frm_login mainly form; User and password is correct, enter the MDI form; Otherwise stay login forms (main form),
Check out other code 2, the basic error free,

As long as the IED, resetting main form,

CodePudding user response:

I also like you, set into child Windows login window,

I define a global variable IsLogon (whether or not the success) and IsFristLogon (whether the login for the first time, or system is already cancelled)

In the main window, the initialization IsLogon to false
Procedure TfrmMain. FormCreate (Sender: TObject);
The begin
IsLogon:=false;
IsFristLogon:=true;
end;

Procedure TfrmMain. FormActivate (Sender: TObject);
The begin
If not IsFristLogon then
The begin
The Exit;
end;
FrmLogonSys:=TfrmLogonSys. Create (Application);
FrmLogonSys. Position:=poMainFormCenter;
FrmLogonSys. ShowModal;
If IsLogon then//login success
The begin
IsFristLogon:=False;
//do something...
End
The else
The begin//login failed, shut off the main form
Postmessage (frmMain. Handle, WM_CLOSE, 0, 0).//as if in FormShow, perform postmessage will go wrong, so I login in the FormActivate response,
end;
end;

//frmLogonSys main content (login)
Put the login judgment in frmLogonSys form inside, only return IsLogon value with respect to OK,

//function by clicking on the login button,
Procedure TfrmLogonSys. BtnLogonClick (Sender: TObject);
The begin
Var SQLSTR: string;
The begin
SQLSTR:='select * from the users where id=' "+ edit1. Text + ' ' 'and PWD='" + edit2. Text + "'" ';
Adoquery1. Close;
Adoquery1. SQL. The Clear;
Adoquery1. SQL. The Add (SQLSTR);
Adoquery1. Open;
If adoquery1. RecordCount & lt;> 0 then
The begin//login successful
IsLogon:=true;
//save the logged in user information to a global variable, such as for system runtime log operation etc,,,
FrmLogonSys. ModalResult:=mrOK;
FrmLogonSys. Close;
End
The else
The begin//login failed,
SysCtrl. IsLogon:=False;
Showmessage (' Logon system failture: User name or password error. ');
EdtRdId. SetFocus;
end;

//click the exit button
Procedure TfrmLogonSys. BtnExitClick (Sender: TObject);
The begin
If MessageDlg (' Are you sure to exit? ', mtConfirmation, [mbYes, mbNo], 0)=mrYes then
The begin
SysCtrl. IsLogon:=False;
The Close;
end;
end;

CodePudding user response:

Under the DPR main project file for modification can

.
Application CreateForm (TFmLogin FmLogin);
If FmLogin. ShowModal () then//reload the Form here. ShowModal
The begin
FmLogin. Free;
Application CreateForm (TFmMain FmMain);
Application. The Run;
End
The else FmLogin. Free;
.

CodePudding user response:

The above a variety of methods, based on personal interests, to consider it,

But I feel, still set login container, give priority to the window, convenient, as long as the login is successful, can enter other modules,

CodePudding user response:

Thank you very much! Tested the login container, in the main window and log in successfully to FRM_MAIN main interface, but the problem comes, when the main interface shown below several MDICHILD
Error: always create a form. No MDI ARE CURRENTLY ACTIVE.


Call the child form code is:
Procedure Tfrm_main. SpeedButton1Click (Sender: TObject);
The begin
//Application CreateForm (TFRM_GHS FRM_GHS);
Frm_ghs:=tfrm_ghs. Create (application);
end;

CodePudding user response:

Frm_ghs forms are available in engineering option form, adjust it to automatically create the form, or to the same fault

CodePudding user response:

It seems problem, no problem, Mid child form, can be used in a dynamic way form,
  • Related