Delphi Login Window Problem [problem points: 30 points, knot person Tianhuo_soft]

Source: Internet
Author: User

http://bbs.csdn.net/topics/200053917

There are two of Windows
Formlogin is the landing window, FormMain is the main window
I want FormMain to show up and Formlogin window closed or hidden
It's a matter of shutting down the formmain and not the Formlogin.
If it's hiding that formmain, you're going to close the Formlogin window.

I think so, I do not understand the mechanism of Delphi ~!

I added in the Formlogin
Formmain:=formmain.create (application);
Formmain.showmodal;
Formlogin.close;
This does not hide Formlogin window, is not to add what statement ~!

Thank you for your answer to this question!

That's what DPR wrote inside (uses Controls)

Begin
Application.initialize;
Application.createform (Tformmain, FormMain);
Formlogin = tformlogin.create (application);
If Formlogin.showmodal = Mrok Then
Begin
Formlogin.release;
Application.Run;
End
End.

My engineering papers are like this.
Application.initialize;
Application.createform (Tformmain, FormMain);
Application.showmainform: = false;
Application.Run;

My idea is to create the FormMain window first in the Formlogin window from the FormMain oncreate event
Formlogin:=tformlogin.create (application);
Formlogin.showmodal;

When the user name and password are entered correctly
Formlogin.free;
Formlogin:=nil;
Formmain.showmodal;

So there's a problem with shutting down FormMain and not shutting down Formlogin.

Procedure Tform1.formcreate (Sender:tobject);
Begin
Formlogin:=tformlogin.create (self);
Try
If Formlogin.showmodal<>mrok Then
Close
Finally
Formlogin.free;
End
End

This is the case in the engineering document.
Begin
Application.initialize;
F_pos_start: = Tf_pos_start. Create (application);
F_pos_start.show;
F_pos_start. Update;
Sleep (2000);
F_pos_start. Close;
Application.title: = ' big pharmacy chain Management system-chain end ';
Application.createform (Tf_pos_main, F_pos_main);
Application.createform (Tf_pos_login, F_pos_login);
.............................
Application.createform (Tf_pos_select_unit, f_pos_select_unit);
Application.createform (Tf_pos_check_stock, F_pos_check_stock);
F_pos_main.visible: = true; Show main form
F_pos_login. ShowModal; Show Login Form
Application.Run;
End.

Release when the login is successful, do a free or something? or Oncolose action:=cafree;

It is recommended to use MDI, so that you can achieve the landlord meaning
Only the main form is created in the project file.
It is then released in the main form after the login dialog is created and completed.

I don't know what you mean.

I'll say my own example.

MainForm main form

LoginForm Login Form

In MainForm's Formshow event, determine if you are currently logged in
If there is. Just loginform.showmodal;

In LoginForm's Formclose event, determine if you are currently logged in
If there is. Just application.terminate.

You set LoginForm as the main form ... Then determine the user name password

Verify through MainForm display ... LoginForm Release

It's supposed to be like this! ! !

ShowModal is a display mode form, only if the form is closed before you can execute the following closing statement
Hide of the form-hidden method

Self.hide; Hide First
Frmmain: = tform.create (application);
Frmmain.showmodal;

Handle_1,handle_2:hwnd;
Begin
Database file Detection
If (Not FileExists (Extractfilepath (paramstr (0)) + ' Up.mdb '), or (Not FileExists (Extractfilepath (paramstr (0)) + ' Handset.mdb ') Then
Begin
MessageBox (0, ' System file is missing, please reinstall! ', ' hint ', MB_OK);
Application.terminate;
End;
Application.initialize;
Get Window Handle
Handle_1:=findwindow (' Tform_handset_login ', nil);
Handle_2:=findwindow (' Tform_handset_main ', nil);
If (handle_1=0) and (handle_2=0) then
Begin
Start the Login window
Form_handset_login:=tform_handset_login.create (application);
Form_handset_login.showmodal;
If (Form_handset_login.modalresult=mrok) Then
Begin
Application.title: = ' phone address book ';
Application.createform (Tform_handset_main, Form_handset_main);
Application.createform (TDM, DM);
Application.Run;
End;
End
Else
MessageBox (0, ' phone Address book already running! ', ' hint ', MB_OK);
End.

Unit Handset_login;

Interface

Uses
Windows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms,
Dialogs, Rzbutton, Stdctrls, Mask, Rzedit, Rzlabel, Extctrls, Rzpanel,
DB, ADODB;

Type
Tform_handset_login = Class (Tform)
Rzgroupbox1:trzgroupbox;
Rzlabel1:trzlabel;
Rzlabel2:trzlabel;
Rzedit1:trzedit;
Rzedit2:trzedit;
RZBITBTN1:TRZBITBTN;
RZBITBTN2:TRZBITBTN;
Adoquery_login:tadoquery;
Procedure Formcreate (Sender:tobject);
Procedure Rzbitbtn1click (Sender:tobject);
Procedure Rzbitbtn2click (Sender:tobject);
Procedure Formclosequery (Sender:tobject; var canclose:boolean);
Procedure Rzedit1keydown (Sender:tobject; var Key:word;
Shift:tshiftstate);
Procedure Rzedit2keydown (Sender:tobject; var Key:word;
Shift:tshiftstate);
Private
{Private declarations}
Public
{Public declarations}
End

Var
Form_handset_login:tform_handset_login;
J:integer=1;
E:boolean=false;
Implementation
Uses AES;
Const
keys= ' Z1a2x2d3cf34r5f5g6h7jk8 ';
{$R *.DFM}
{------------------------------------------------------------------------------}
1 initialization: The database of the associated data
{------------------------------------------------------------------------------}
Procedure Tform_handset_login.formcreate (Sender:tobject);
Const
password= ' q1w2e3r4t5y6u7i8o9p0 ';
Var
mypath:string;
Begin
Rzedit1.clear;
Rzedit2.clear;
----------------------------Connect to the database----------------------------------------
Mypath:=extractfilepath (paramstr (0));
Adoquery_login.connectionstring: = ' Provider=Microsoft.Jet.OLEDB.4.0;Data source= ' +
mypath+ ' Up.mdb; Jet oledb:database password= ' +
Password+ '; Persist Security Info=false ';
End
{------------------------------------------------------------------------------}
2 judgement
{------------------------------------------------------------------------------}
Procedure Tform_handset_login.rzbitbtn1click (Sender:tobject);
Var
username,password:string;
Begin
Adoquery_login.close;
ADOQuery_Login.SQL.Clear;
ADOQuery_Login.SQL.Add (' Select *from Login ');
Adoquery_login.open;
If Adoquery_login.recordcount>0 Then
Begin
Adoquery_login.first;
Username:=decryptstring (adoquery_login.fieldvalues[' UserName '), Keys);
Password:=decryptstring (adoquery_login.fieldvalues[' PassWord '), Keys);
If (Trim (UserName) =trim (Rzedit1.text)) and (Trim (PassWord) =trim (rzedit2.text)) Then
Begin
Self.modalresult:=mrok;
End
Else
Begin
If J=3 Then
Begin
Messagebox (handle, ' illegal login! ', ' system hint ', mb_ok+mb_iconerror);
Adoquery_login.close;
Application.terminate; Exit system
End;
MessageBox (handle, ' username or password is incorrect, please re-fill! ', ' hint ', mb_ok+mb_iconinformation);
j:=j+1;
Rzedit1.clear;
Rzedit2.clear;
Rzedit1.setfocus;
End;
End;
End
{------------------------------------------------------------------------------}
3 exit
{------------------------------------------------------------------------------}
Procedure Tform_handset_login.rzbitbtn2click (Sender:tobject);
Begin
E:=true;
Close
End
{------------------------------------------------------------------------------}
4 Exit Judgment
{------------------------------------------------------------------------------}
Procedure Tform_handset_login.formclosequery (Sender:tobject;
var canclose:boolean);
Begin

If E=true Then
Begin
Adoquery_login.close;
Application.terminate;
End
End
{------------------------------------------------------------------------------}
5 Toggle Focus
{------------------------------------------------------------------------------}
Procedure Tform_handset_login.rzedit1keydown (Sender:tobject;
var Key:word; Shift:tshiftstate);
Begin
If Key=vk_return Then
Rzedit2.setfocus
End
{------------------------------------------------------------------------------}
6 Toggle Focus
{------------------------------------------------------------------------------}
Procedure Tform_handset_login.rzedit2keydown (Sender:tobject;
var Key:word; Shift:tshiftstate);
Begin
If Key=vk_return Then
Rzbitbtn1click (Sender);
End

End.

Program handset;

Uses
Forms,
Windows
Sysutils,
Controls
Handset_main in ' Handset_main.pas ' {form_handset_main},
MyData in ' Mydata.pas ' {dm:tdatamodule},
Handset_edit in ' Handset_edit.pas ' {form_handset_edit},
Handset_search in ' Handset_search.pas ' {form_handset_search},
Handset_qz in ' Handset_qz.pas ' {FORM_HANDSET_QZ},
HANDSET_LX in ' Handset_lx.pas ' {FORM_HANDSET_LX},
Handset_login in ' Handset_login.pas ' {form_handset_login},
Handset_safety in ' Handset_safety.pas ' {form_handset_safety};

{$R *.res}
Var
Handle_1,handle_2:hwnd;
Begin
Database file Detection
If (Not FileExists (Extractfilepath (paramstr (0)) + ' Up.mdb '), or (Not FileExists (Extractfilepath (paramstr (0)) + ' Handset.mdb ') Then
Begin
MessageBox (0, ' System file is missing, please reinstall! ', ' hint ', MB_OK);
Application.terminate;
End;
Application.initialize;
Get Window Handle
Handle_1:=findwindow (' Tform_handset_login ', nil);
Handle_2:=findwindow (' Tform_handset_main ', nil);
If (handle_1=0) and (handle_2=0) then
Begin
Start the Login window
Form_handset_login:=tform_handset_login.create (application);
Form_handset_login.showmodal;
If (Form_handset_login.modalresult=mrok) Then
Begin
Application.title: = ' phone address book ';
Application.createform (Tform_handset_main, Form_handset_main);
Application.createform (TDM, DM);
Application.Run;
End;
End
Else
MessageBox (0, ' phone Address book already running! ', ' hint ', MB_OK);
End.

Delphi Login Window Problem [problem points: 30 points, knot person Tianhuo_soft]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.