1. 程式人生 > >如何在主Form出現之前,彈出密碼驗證From,Cancel就退出程序,Ok後密碼正確才出現主Form

如何在主Form出現之前,彈出密碼驗證From,Cancel就退出程序,Ok後密碼正確才出現主Form

標題 fin name ole nbsp close bob dial 作用

如何在主Form出現之前,彈出密碼驗證From,Cancel就退出程序,Ok後密碼正確才出現主Form
本文地址 :CodeGo.net/5175478/
-------------------------------------------------------------------------------------------------------------------------
1.我給你一個LOGINFORM的例子:
unit LoginFrm;
interface
uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls;
type
TLoginForm = class(TForm)
lblEnterPassword: TLabel;
lblEnterName: TLabel;
edtName: TEdit;
edtPassword: TEdit;
btnOK: TButton;
btnCancel: TButton;
public
end;
function GetLoginParams(ALoginParams: TStrings): Boolean;
implementation
{$R *.DFM}
function GetLoginParams(ALoginParams: TStrings): Boolean;
var
LoginForm: TLoginForm;
begin
Result := False;
LoginForm := TLoginForm.Create(Application);
try
if LoginForm.ShowModal = mrOk then
begin
ALoginParams.Values[‘USER NAME‘] := LoginForm.edtName.Text;
ALoginParams.Values[‘PASSWORD‘] := LoginForm.edtPassWord.Text;
Result := True;
end;
finally
LoginForm.Free;
end;
end;
end.
2. 自己先做個登錄窗體
在工程文件裏先USES 那個單元
再寫......
Application.Initialize;
frmlogon:= Tfrmlogon.Create(Application);
frmlogon.ShowModal;
frmlogon.Update;
if frmlogon.ModalResult = mrOK then
begin
frmlogon.Free;
frmlogon.Hide;
Application.CreateForm(TForm1, Form1);
Application.Run;
end
3. procedure TLoginForm.btnLoginClick(Sender: TObject);
var
ComputerName: String;
CNameBuffer : PChar;
fl_loaded : Boolean;
CLen : ^DWord;
intLogin:Integer;
begin
//取得計算機名稱
GetMem(CNameBuffer,255);
New(CLen);
CLen^:= 255;
fl_loaded := GetComputerName(CNameBuffer,CLen^);
if fl_loaded then
ComputerName := StrPas(CNameBuffer)
else
ComputerName := ‘Unknown‘;
FreeMem(CNameBuffer,255);
Dispose(CLen);
//登錄系統
if edtUser.Text=‘‘ then
begin
MessageBox(Self.Handle,‘輸入用戶!‘,‘提示‘,MB_OK+MB_ICONEXCLAMATION);
edtUser.SetFocus;
exit;
end;
if ComboBox1.items.Count>0 then
begin
if ComboBox1.ItemIndex=-1 then
begin
MessageBox(Self.Handle,‘選擇帳套!‘,‘提示‘,MB_OK+MB_ICONEXCLAMATION);
ComboBox1.SetFocus;
exit;
end;
end;
//登錄系統
if blnFirstLogin=False then dmlPreserve.scPreserve.AppServer.LogoutStatus(CurUserID);
dmlPreserve.scPreserve.AppServer.LoginStatus(edtUser.Text,edtPwd.Text,ComputerName,intLogin,curUserName);
Case intLogin of
0: //成功登錄
begin
MessageBox(Self.Handle,‘登錄成功!‘,‘提示‘,MB_OK+MB_ICONEXCLAMATION);
Fini.WriteString(‘Preserve‘,‘LastUser‘,edtUser.Text);
Fini.WriteString(‘Preserve‘,‘LastAccount‘,ComboBox1.Text);
curAccount:=ComboBox1.Text;
MDIMainForm.sbrMain.Panels[3].Text:=‘當前帳套:‘+ComboBox1.Text;
curUserID:=edtUser.Text;
MDIMainForm.sbrMain.Panels[2].Text:=‘操作用戶:‘+curUserName;
dmlPreserve.cdsusrUser.Close;
if blnFirstLogin=True then blnFirstLogin:=False;
Close;
end;
1:
begin
MessageBox(Self.Handle,‘該用戶不存在!‘,‘提示‘,MB_OK+MB_ICONEXCLAMATION);
edtUser.SetFocus;
end;
2:
begin
MessageBox(Self.Handle,‘該用戶不允許在此計算機上登錄!‘,‘提示‘,MB_OK+MB_ICONEXCLAMATION);
edtUser.SetFocus;
end;
3:
begin
MessageBox(Self.Handle,‘密碼錯誤!‘,‘提示‘,MB_OK+MB_ICONEXCLAMATION);
edtPwd.SetFocus;
end;
4:
begin
MessageBox(Self.Handle,‘該用戶已經登錄!‘,‘提示‘,MB_OK+MB_ICONEXCLAMATION);
edtUser.SetFocus;
end;
5:
begin
if MessageBox(Self.Handle,‘該用戶已經登錄,是否強行登錄?‘,‘提示‘,MB_YESNO+MB_ICONQUESTION)=mrNO then
edtUser.SetFocus;
end;
6:
begin
MessageBox(Self.Handle,‘登錄中遇到未知錯誤!‘,‘錯誤‘,MB_OK+MB_ICONEXCLAMATION);
edtUser.SetFocus;
end;
end;
end
4. procedure TMDIMainForm.MDIMainFormOnActivate(Sender: TObject);
begin
LoginForm:=TLoginForm.Create(Self);
LoginForm.ShowModal ;
end;
procedure TLoginForm.btnCancelClick(Sender: TObject);
begin
Application.Terminate
end
5. program Project1;
uses
Forms,
Dialogs,
Unit1 in ‘Unit1.pas‘ {Form1};
{$R *.RES}
Var
Pass:String;
begin
Application.Initialize;
InputQuery(‘密碼‘,‘輸入密碼‘,Pass);
if Pass<>‘OK‘ then Application.Terminate;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
本文標題 :如何在主Form出現之前,彈出密碼驗證From,Cancel就退出程序,Ok後密碼正確才出現主Form
本文地址 :CodeGo.net/5175478/

如何在主Form出現之前,彈出密碼驗證From,Cancel就退出程序,Ok後密碼正確才出現主Form