源码如下:unit Unit2;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TForm2 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation
uses unit1;
{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
var i:integer;
begin
i:=0 ; if (edit1.Text=' ') or (edit2.Text=' ') then
showmessage('用户名或密码不能为空') else
begin
while i<=adotable1.RecordCount do
begin
if (adotable1.FieldByName('id').AsString=edit1.Text) and (adotable1.FieldByName('password').AsString=edit2.Text) then
begin
form1.Enabled:=true;//验证密码,密码表放在access中,有多个帐号
form2.Close; exit;
end
else
adotable1.Next;
i:=i+1;
end;
if i>adotable1.RecordCount then
showmessage('用户名或密码错误');
form1.Close; end;end;
procedure TForm2.Button2Click(Sender: TObject);
begin
close;
form1.Close;
end;end.
可是我不输入密码,直接关闭登陆框(form2)时form1却跳了出来
求大人帮我去掉这个bug(应该在某处加上一句代码),谢谢啊
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TForm2 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form2: TForm2;implementation
uses unit1;
{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
var i:integer;
begin
i:=0 ; if (edit1.Text=' ') or (edit2.Text=' ') then
showmessage('用户名或密码不能为空') else
begin
while i<=adotable1.RecordCount do
begin
if (adotable1.FieldByName('id').AsString=edit1.Text) and (adotable1.FieldByName('password').AsString=edit2.Text) then
begin
form1.Enabled:=true;//验证密码,密码表放在access中,有多个帐号
form2.Close; exit;
end
else
adotable1.Next;
i:=i+1;
end;
if i>adotable1.RecordCount then
showmessage('用户名或密码错误');
form1.Close; end;end;
procedure TForm2.Button2Click(Sender: TObject);
begin
close;
form1.Close;
end;end.
可是我不输入密码,直接关闭登陆框(form2)时form1却跳了出来
求大人帮我去掉这个bug(应该在某处加上一句代码),谢谢啊
判断密码正确后Form1.ModalResult := rmok;就可以
你的判断密码的方法也有问题可以把户名和加密的密码同时生成SQL语句查有多少条记录来判断就可以
if i<=adotable1.RecordCount then 中去掉等于
你的form1是不是主窗体
如果是主窗体就再验证信息不通过切要关闭form2时也将form1关闭
或者用application.terminate;结束整个程序
强行结束应用程序可以用Halt或者楼上说的
program x2000;uses
Forms,
Emain in 'Emain.pas' {EmsgFrm},
Elogin in 'Elogin.pas' {EloginFrm},{$R *.res}begin
Application.Initialize;
Application.Title := 'xxx';
EloginFrm:=TEloginFrm.Create(Application);
if EloginFrm.ShowModal=1
then begin
Application.CreateForm(TEmsgFrm, EmsgFrm);//相当Form1
Application.Run;
end;
end.