procedure TForm1.FormCreate(Sender: TObject);
begin
        self.Caption :=application.Title + ' - ';
        self.Caption :=self.Caption +'用户登录';
        I_logo:=0;
        with table1 do
        begin
        close;
        DatabaseName:='DBDEMOS';
        TableName :='D:\Program Files\Common Files\Borland Shared\Database Desktop\WorkDir\user.db';
        open;
        end;
        table1.First;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
application.Terminate ;
end;procedure TForm1.Button1Click(Sender: TObject);
var
        username,password:string;begin
      username:=edit1.Text ;
      password:=edit2.Text ;       with table1 do
       begin        while not table1.eof do   //检查用户名与密码
         begin            if(username=table1.FieldByName('username').AsString) and (password=table1.FieldByName('password').AsString) then
            begin
               messagedlg('您的密码正确,你是合法的用户!',mtInformation,[mbok],0);
               table1.first;
               break;
            end;
            table1.Next ;
         end; //end while
         if table1.eof then
         begin
                inc(I_logo);
                if I_logo>=3 then
                begin
                //messagedlg('您已尝试超过 3 次,系统将停止运行!',mterror,[mbok],0);
                table1.Close ;
                table1.Free;
                //close;
                application.Terminate ;
                exit;
                end
                else
                begin
                messagedlg('用户名与密码不符,请检查后重新输入。'+#13+#13
                  +'你还有 '+inttostr(3-I_logo)+' 次机会!',mterror,[mbok],0);
               edit1.SetFocus ;
               edit1.Text :='';
               edit2.Text :='';
               exit;
               end;
         end;
        end;
         table1.close;
         table1.Free;end;procedure TForm1.Edit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
if key=13 then button1.onclick(self);
if key=27 then button2.onclick(self);
end;end.
老是出错大家看一下,出错地方就是while not table1.eof do   //检查用户名与密码
这个地方,不知道什么地方搞错啦!!谢谢大家!!

解决方案 »

  1.   

    应该是连接数据的问题.
    设置 loginprompt=false
      

  2.   

    看你的代码,既然有With 那么下面可以省略的为什么还要画蛇添足。       with table1 do
           begin        while not table1.eof do   //检查用户名与密码
             begin还有请把Delphi的错误信息也贴出来吧。
      

  3.   

    好像你没有在Table中写SQL语句, 是在Object Inspector中写了么?
      

  4.   

    在下面的语句之前加上(Table1.Open;
                        Table1.First )
                        试一试看!
                         
            while not table1.eof do   //检查用户名与密码
             begin