P
phillips
Unregistered / Unconfirmed
GUEST, unregistred user!
比如第一次运行的时候运行登录窗体输入了正确的用户名和密码,就把用户名和密码写入注册表,然后打开主窗体.以后运行的时候就提取注册表里面的用户名和密码进行比较,如果正确就直接打开主窗体,不正确就打开登录窗体.
热心的朋友帮忙给看看。应该如何改改才能实现这个效果 。
登录窗体:
unit Loginu;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls,Inifiles,Registry;
type
TLoginfrm = class(TForm)
Label1: TLabel;
GroupBox1: TGroupBox;
Label2: TLabel;
PassWord_Edit: TEdit;
User_Edit: TEdit;
LoginBtn: TBitBtn;
ExitBtn: TBitBtn;
Panel1: TPanel;
Panel2: TPanel;
procedure FormShow(Sender: TObject);
procedure ExitBtnClick(Sender: TObject);
procedure LoginBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Loginfrm: TLoginfrm;
implementation
Uses Mainu;
{$R *.dfm}
procedure TLoginfrm.FormShow(Sender: TObject);
begin
User_Edit.Text :='';
PassWord_Edit.Text :='';
User_Edit.SetFocus();
end;
procedure TLoginfrm.ExitBtnClick(Sender: TObject);
begin
if Application.MessageBox('真的要退出登录吗?','确认信息',MB_IconQuestion+MB_YesNO)=IDYES then
Application.Terminate;
end;
procedure TLoginfrm.LoginBtnClick(Sender: TObject);
var
Reg:TRegistry;
begin
if user_edit.Text<>'1' then
showmessage('输入用户名错误')
else
if password_edit.Text<>'1' then
showmessage('输入密码错误')
else
begin
showmessage('登录成功');
Reg := TRegistry.Create;
with reg do
begin
RootKey:= HKEY_LOCAL_MACHINE;
CreateKey('/Software/111');
OpenKey('Software/111',True);
WriteString('user','1');
WriteString('password','1');
CloseKey;
Destroy;
end;
Self.ModalResult :=1;
end;
end;
end.
----------
工程文件代码
program LegMan_pro;
uses
Forms,
Loginu in 'Loginu.pas' {Loginfrm},
Mainu in 'Mainu.pas' {Mainfrm};
var
Login :TLoginfrm;
{$R *.res}
begin
Application.Initialize;
Login :=TLoginfrm.Create(Application);//登录窗口
if Login.ShowModal =1 then //登录窗口关闭时返回的值为1,说明登录成功
begin
Application.CreateForm(TMainfrm, Mainfrm);
end;
Login.Free();
Application.Run;
end.
热心的朋友帮忙给看看。应该如何改改才能实现这个效果 。
登录窗体:
unit Loginu;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls,Inifiles,Registry;
type
TLoginfrm = class(TForm)
Label1: TLabel;
GroupBox1: TGroupBox;
Label2: TLabel;
PassWord_Edit: TEdit;
User_Edit: TEdit;
LoginBtn: TBitBtn;
ExitBtn: TBitBtn;
Panel1: TPanel;
Panel2: TPanel;
procedure FormShow(Sender: TObject);
procedure ExitBtnClick(Sender: TObject);
procedure LoginBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Loginfrm: TLoginfrm;
implementation
Uses Mainu;
{$R *.dfm}
procedure TLoginfrm.FormShow(Sender: TObject);
begin
User_Edit.Text :='';
PassWord_Edit.Text :='';
User_Edit.SetFocus();
end;
procedure TLoginfrm.ExitBtnClick(Sender: TObject);
begin
if Application.MessageBox('真的要退出登录吗?','确认信息',MB_IconQuestion+MB_YesNO)=IDYES then
Application.Terminate;
end;
procedure TLoginfrm.LoginBtnClick(Sender: TObject);
var
Reg:TRegistry;
begin
if user_edit.Text<>'1' then
showmessage('输入用户名错误')
else
if password_edit.Text<>'1' then
showmessage('输入密码错误')
else
begin
showmessage('登录成功');
Reg := TRegistry.Create;
with reg do
begin
RootKey:= HKEY_LOCAL_MACHINE;
CreateKey('/Software/111');
OpenKey('Software/111',True);
WriteString('user','1');
WriteString('password','1');
CloseKey;
Destroy;
end;
Self.ModalResult :=1;
end;
end;
end.
----------
工程文件代码
program LegMan_pro;
uses
Forms,
Loginu in 'Loginu.pas' {Loginfrm},
Mainu in 'Mainu.pas' {Mainfrm};
var
Login :TLoginfrm;
{$R *.res}
begin
Application.Initialize;
Login :=TLoginfrm.Create(Application);//登录窗口
if Login.ShowModal =1 then //登录窗口关闭时返回的值为1,说明登录成功
begin
Application.CreateForm(TMainfrm, Mainfrm);
end;
Login.Free();
Application.Run;
end.