procedure TForm1.BitBtn1Click(Sender: TObject);
var
  password:string;
  UserName:string;
  QX:string;
  logintimes:integer;begin
adoquery1.SQL.Clear;
adoquery1.SQL.Add('select 密码,权限 from f_user');
adoquery1.SQL.Add('where 姓名=:姓名');
adoquery1.Parameters.ParamByName('姓名').Value:=ComboBox1.Text;
adoquery1.Open;
if adoquery1.RecordCount>0 then
   begin
       password:=adoquery1.FieldValues['密码'];
       if edit1.Text=password then
         begin
            UserName:=ComboBox1.Text;
            self.Hide;
            QX:=adoquery1.FieldValues['权限'];
            with form2.Create(nil) do
              try
                ShowModal;
                finally
                  free;
                  end;
              end
          else
              begin
              logintimes:=0;
                logintimes:=logintimes+1;
                if logintimes<3 then
                  begin
                   messagebox(handle,pchar('密码'+inttostr(logintimes)+
                    '次错误,请重新摄入!'),'密码错误',mb_ok or mb_iconerror);
                   edit1.Text:='';
                   edit1.SetFocus;
                 end
               else
                 begin
                   messagebox(handle,'密码三次错误请关闭!','密码错误',mb_iconerror);
                   application.Terminate;
                 end;
               end;
               end;
          adoquery1.Close;
          freeandnil(adoquery1);
end;错误提示
Project Project1.exe raised exception class EAccesViolation with message'Access violation at address 0048D464 in module' Project1.exe.Read of address 00000258'.Process stopped.Use Step or Run to continue.

解决方案 »

  1.   

     with Tform2.Create(nil) do
      

  2.   

    楼上正确
    另:adoquery1不是动态创建的,不需要freeandnil();
      

  3.   

    adoquery1.Close;
      freeandnil(adoquery1);
    TForm1 form2 那个是主界面?
    搞混了 也不行的 一般登录界面为主界面
      

  4.   

    我把freeandnil();去掉了 怎么运行还是这个错误提示啊
      

  5.   

    这个with Tform2.Create(nil) do 也改了 T加上了
      

  6.   

    begin
      Application.Initialize;
      Application.CreateForm(TForm1, Form1);
      Application.CreateForm(TForm2, Form2);
      Application.Run;
    end.  提示的这个地方好像不对
      

  7.   

    adoquery1.SQL.Clear;
    前面掉了个adoquery1.CLOSE,其它地方我也没看出来了,不知道中断在哪?
      

  8.   

    Application.CreateForm(TForm2, Form2);
    这句话去掉,再试试
      

  9.   

    打个断点跟踪一下,肯定是某个地方被你释放了,某个对象为nil时肯定会报内存错误了
      

  10.   

    跟踪测试一下,最好能在CREATE中设置这些参数
      

  11.   

    对的,去掉这个。 你是让FORM2以模态窗口形式建立。showmodel是不能在启动窗口里有的。