new一个对话框窗口:
unit loginUnit;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, jpeg;
type
Tlogin = class(TForm)
OKBtn: TButton;
CancelBtn: TButton;
Bevel1: TBevel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
private
{ Private declarations }
public
{ Public declarations }
end;
var
login: Tlogin;
implementation
{$R *.DFM}
end.
在主窗口的formcreat()里加入:
login:=TLogin.Create(nil);
check_password(1);
其中的check_password()函数:
procedure tkhyygl.check_password(trytimes:integer);
var
trtm:integer;
begin
trtm:=trytimes+1;
if(login.showmodal=mrok)and(trtm<4) then
begin
username:=trim(login.edit1.Text);
password:=trim(login.edit2.text);
query.Close();
query.Prepare;
query.SQL.Clear;
query.SQL.Add('SELECT * FROM table');
query.SQL.Add('WHERE NAME='''+username+''' and PASSWORD='''+password+'''');
try
query.ExecSQL;
query.Open;
if (Query.EOF)then
begin
application.MessageBox('你的输入不正确!',' 错误',IDOK);
if(trtm<4)then
check_password(trtm)
else
application.Terminate;
end
else
bz:=query.FieldByname('BZ').Asstring;
except
application.MessageBox('无法访问数据库!',' 错误',IDOK);
application.Terminate;
end;
end
else
begin
application.Terminate;
end;
end;
该函数可以上用户尝试四次输入,四次后自动退出。
unit loginUnit;
interface
uses Windows, SysUtils, Classes, Graphics, Forms, Controls, StdCtrls,
Buttons, ExtCtrls, jpeg;
type
Tlogin = class(TForm)
OKBtn: TButton;
CancelBtn: TButton;
Bevel1: TBevel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
private
{ Private declarations }
public
{ Public declarations }
end;
var
login: Tlogin;
implementation
{$R *.DFM}
end.
在主窗口的formcreat()里加入:
login:=TLogin.Create(nil);
check_password(1);
其中的check_password()函数:
procedure tkhyygl.check_password(trytimes:integer);
var
trtm:integer;
begin
trtm:=trytimes+1;
if(login.showmodal=mrok)and(trtm<4) then
begin
username:=trim(login.edit1.Text);
password:=trim(login.edit2.text);
query.Close();
query.Prepare;
query.SQL.Clear;
query.SQL.Add('SELECT * FROM table');
query.SQL.Add('WHERE NAME='''+username+''' and PASSWORD='''+password+'''');
try
query.ExecSQL;
query.Open;
if (Query.EOF)then
begin
application.MessageBox('你的输入不正确!',' 错误',IDOK);
if(trtm<4)then
check_password(trtm)
else
application.Terminate;
end
else
bz:=query.FieldByname('BZ').Asstring;
except
application.MessageBox('无法访问数据库!',' 错误',IDOK);
application.Terminate;
end;
end
else
begin
application.Terminate;
end;
end;
该函数可以上用户尝试四次输入,四次后自动退出。
非常感谢!
经你提点,我已全部运行通过!
希望以后更加友好合作! Peterwjb2000