procedure TForm1.Image4Click(Sender: TObject); var ADOQuery1: TADOQuery; begin {数据库操作:判断用户和密码是否正确} if (edit1.Text<>'') and (edit2.Text<>'') then begin ChDir(ExtractFilePath(Application.ExeName)); ChDir('..'); ExeRoot := GetCurrentDir; DataFile := GetCurrentDir+'\Data\dzyv1.mdb'; ADOQuery1:= TADOQuery.Create(self); ADOQuery1.ConnectionString := 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source='+DataFile+';Persist Security Info=False;'; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('select * from t_user where user_name="'+edit1.Text+'" and user_pass="'+edit2.Text+'" '); ADOQuery1.Open; if ADOQuery1.Eof then begin LogTimes := LogTimes+1; if messagebox(handle,'您填写的用户或密码有错误!是否重新输入?','出错提示',mb_iconinformation+mb_okcancel)=IDcancel then application.Terminate; if LogTimes>=3 then begin messagebox(handle,'对不起,登录次数超过3次,程序自动关闭!','非法登录',MB_ICONWARNING+mb_ok); application.Terminate; end; end else begin {用户和密码正确,登录成功} UserType := ADOQuery1.FieldByName('user_type').AsString; UserName := ADOQuery1.FieldByName('user_name').AsString; LogTimes := 0; ADOQuery1.Free; Form1.Hide; form2.ShowModal; end; end else messagebox(handle,'您没有填写用户和密码!','出错提示',mb_iconinformation+mb_ok) end;