unit Unit2;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, ADODB;type
  TForm2 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    ADOTable1: TADOTable;
    DataSource1: TDataSource;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form2: TForm2;implementationuses Unit1;{$R *.dfm}procedure TForm2.Button1Click(Sender: TObject);
var
conn:string;
i:integer;
mypath:string;
mimi:string;
begin
  if edit1.Text='' then
   begin
      showmessage('用户名不能不填吧?!!');
      edit1.SetFocus;
   end
   else if edit2.Text='' then
          begin
            showmessage('密码忘了写!!');
            edit2.SetFocus;
          end
  else
    begin
      conn:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+mypath+'data\student.mdb;Persist Security Info=False';
      adotable1.ConnectionString:=conn;
      adotable1.TableName:='admin';
      adotable1.Open;
      adotable1.First;
          while not adotable1.Eof do
          begin
            i:=0;
              if (trim(edit1.Text)=trim(adotable1.Fields[1].AsString)) and  (trim(edit2.Text)=trim(adotable1.Fields[2].AsString)) then
              begin
                form1.Show;
                i:=i+1;
              end
              else
                    adotable1.Next;
              end;
              if i=0 then
              begin
                  if  (trim(edit1.Text)<>trim(adotable1.Fields[1].AsString)) then
                    begin
                      showmessage('无此用户名');
                        exit;
                    end;
                  if  (trim(edit2.Text)<>trim(adotable1.Fields[2].AsString)) then
                    begin
                      showmessage('密码不正确');
                    end;
              end;
      end;
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
   edit1.Text:='';
   edit2.Text:='';
end;end.
出现死循环

解决方案 »

  1.   

    procedure TForm2.Button1Click(Sender: TObject);
    var
    conn:string;
    i:integer;
    mypath:string;
    mimi:string;
    begin
      if edit1.Text='' then
       begin
          showmessage('用户名不能不填吧?!!');
          edit1.SetFocus;
          exit;//////////////////////
       end
       else if edit2.Text='' then
              begin
                showmessage('密码忘了写!!');
                edit2.SetFocus;
                exit;////////////
              end
      else
        begin
          conn:='Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+mypath+'data\student.mdb;Persist Security Info=False';
          adotable1.ConnectionString:=conn;
          adotable1.TableName:='admin';
          adotable1.Open;
          adotable1.First;
              while not adotable1.Eof do
              begin
                i:=0;
                  if (trim(edit1.Text)=trim(adotable1.Fields[1].AsString)) and  (trim(edit2.Text)=trim(adotable1.Fields[2].AsString)) then
                  begin
                    form1.Show;
                    i:=i+1;
                    break;///////////////////////
                  end
                  else
                        adotable1.Next;
                  end;
                  if i=0 then
                  begin
                      if  (trim(edit1.Text)<>trim(adotable1.Fields[1].AsString)) then
                        begin
                          showmessage('无此用户名');
                            exit;
                        end;
                      if  (trim(edit2.Text)<>trim(adotable1.Fields[2].AsString)) then
                        begin
                          showmessage('密码不正确');
                        end;
                  end;
          end;
    end;
    procedure TForm2.FormCreate(Sender: TObject);
    begin
       edit1.Text:='';
       edit2.Text:='';
    end;end.
    出现死循环
    ///是你要加的,还有,去掉I吧,没什么用的:)