access violation at address 

解决方案 »

  1.   

    var FF:TForm2;
    begin
      FF := TForm2.Create(Self);
      FF.ShowModel;
    end;
      

  2.   

    var FF:TForm2;
    begin
      FF := TForm2.Create(Self);
      try
        FF.ShowModel;
      finally
        ff.free;
      end;
    end;
      

  3.   

    那你就看看你在 TForm2 的 onformShow里写了什么。
      

  4.   

    对,你查一下TForm2的代码。access violation(AV错误)一般是没有申请内存或者对象就直接用了。
      

  5.   


    uses Form2;var
      FF: TForm2;
    begin
      if not Assigned(FF) then
    //ShowMessage('The Form2 is not Assigned!');  
      FF := TForm2.Create(Self);
      FF.ShowModal;
    end;
      

  6.   

       if fShow_pay=nil then
        fshow_Pay:= Tfshow_Pay.Create(Self);
        fshow_Pay.Label15.caption:= Edit11.text;
        fshow_Pay.Label5.caption := Edit11.text;
        nselfPay                 := GetNewPay(nPerPay + nSelfToCo);
        fshow_Pay.Label16.caption:= format('%5.2f',[nselfPay]);
        fshow_Pay.Label6.caption := format('%5.2f',[nCardPay]);
        fshow_Pay.Label7.caption := format('%5.2f',[nselfPay]);
        fshow_Pay.Label8.caption := format('%5.2f',[nselfPay+nCardPay]);
        fshow_Pay.Edit1.Text     := '0';
        Label11.Caption :='0';
        fshow_Pay.mode           := (bYb='1');
        if bYb='1' then
        begin
          fShow_pay.GroupBox2.Visible:=True;
        end
        else
        begin
          fShow_pay.GroupBox2.Visible:=True;
          fShow_pay.GroupBox1.Visible:=True;
        end;
        fshow_Pay.pay            := nselfPay;
        fShow_pay.ShowModal;
      

  7.   


    //代码很乱。
    if fShow_pay=nil then
    fshow_Pay:= Tfshow_Pay.Create(Self);
    {
    fshow_Pay.Label15.caption:= Edit11.text;
    fshow_Pay.Label5.caption := Edit11.text;
    nselfPay := GetNewPay(nPerPay + nSelfToCo);
    fshow_Pay.Label16.caption:= format('%5.2f',[nselfPay]);
    fshow_Pay.Label6.caption := format('%5.2f',[nCardPay]);
    fshow_Pay.Label7.caption := format('%5.2f',[nselfPay]);
    fshow_Pay.Label8.caption := format('%5.2f',[nselfPay+nCardPay]);
    fshow_Pay.Edit1.Text := '0';
    Label11.Caption :='0';
    fshow_Pay.mode := (bYb='1');
    if bYb='1' then
    begin
    fShow_pay.GroupBox2.Visible:=True;
    end
    else
    begin
    fShow_pay.GroupBox2.Visible:=True;
    fShow_pay.GroupBox1.Visible:=True;
    end;
    fshow_Pay.pay := nselfPay;
    } //把注视掉的这一块放到一个函数里面去做
    fShow_pay.ShowModal;
      

  8.   


    with Tfshow_Pay.Create(Self) do
     begin
      初始化部分
      //Label15.caption:= Edit11.text;
       ……
      showmodal;
      free;
     end;
      

  9.   

    仔细看看 跟踪下看到那步出错最前面加这样一句 if assigned(lform) then freeandnil(lform);
      

  10.   

    fShow_pay.free 指针不会指空  你判断fShow_pay=nil 肯定得到的结果是false 
      

  11.   

    我可以负责任地告诉楼主,SHOWMODAL用了不可能本身有错。提醒下,你还要检查你那些事件的代码,例如ONSHOW之类,单步调试吧
      

  12.   

    另外就是释放对象后是否同时把对象引用置为NIL,否则重新判断的时候,会判断不出是不是NIL(对象到底有没被创建)。
      

  13.   

    if fShow_pay=nil then //你这个地方判断指针为空,fShow_pay.free时,指针肯定不为空的。这个判断有问题。
    with Tfshow_Pay.Create(Self) do
    begin
    fshow_Pay:= Tfshow_Pay.Create(Self);//初始化。
    fshow_Pay.Label15.caption:= Edit11.text;
    fshow_Pay.Label5.caption := Edit11.text;
    nselfPay := GetNewPay(nPerPay + nSelfToCo);
    fshow_Pay.Label16.caption:= format('%5.2f',[nselfPay]);
    fshow_Pay.Label6.caption := format('%5.2f',[nCardPay]);
    fshow_Pay.Label7.caption := format('%5.2f',[nselfPay]);
    fshow_Pay.Label8.caption := format('%5.2f',[nselfPay+nCardPay]);
    fshow_Pay.Edit1.Text := '0';
    Label11.Caption :='0';
    fshow_Pay.mode := (bYb='1');
    if bYb='1' then
    begin
    fShow_pay.GroupBox2.Visible:=True;
    end
    else
    begin
    fShow_pay.GroupBox2.Visible:=True;
    fShow_pay.GroupBox1.Visible:=True;
    end;
    fshow_Pay.pay := nselfPay;
    fShow_pay.ShowModal;
    end;
      

  14.   


    if not Assigend(fShow_pay) then 
      fShow_pay:= TfShow_pay.create(application);  with Tfshow_Pay.Create(Self) do
      begin  end;
    fShow_pay.ShowModal;
    end;
      

  15.   

    不要用Form.ShowModal,你直接用Form.Show试试看。