FormSjbf:=TFormSjbf.Create(Application);
  FormSjbf.Show;在另外一个窗体内,建立一个按钮,目的上按了这个按钮后就释放窗体:formsjbf,
我用的是formsjbf.release,但提示出错,用formsjbf.free也出错,请问这是怎么回事?如何解决?谢谢.

解决方案 »

  1.   

    用free应该没有任何问题。你把报的错贴出来看看
      

  2.   

    当然出错了,看看窗体的close 干了多少事情,你简单的Free能不出错吗?
    procedure TCustomForm.Close;
    var
      CloseAction: TCloseAction;
    begin
      if fsModal in FFormState then
        ModalResult := mrCancel
      else
        if CloseQuery then
        begin
          if FormStyle = fsMDIChild then
            if biMinimize in BorderIcons then
              CloseAction := caMinimize else
              CloseAction := caNone
          else
            CloseAction := caHide;
          DoClose(CloseAction);
          if CloseAction <> caNone then
            if Application.MainForm = Self then Application.Terminate
            else if CloseAction = caHide then Hide
            else if CloseAction = caMinimize then WindowState := wsMinimized
            else Release;
        end;
    end;
      

  3.   

    我用了formsjbf.free后,按了按钮却没有任何反应,窗体没有关闭,也没有出错。
      

  4.   

    FormSjbf:=TFormSjbf.Create(Application);
    try
      FormSjbf.ShowModal;
    finally
      FormSjbf.free;
      FormSjbf:=nil;
    end;
    这样close;以后就自动释放了
      

  5.   

    to dh9450
    不行啊,弹出出错对话框
      

  6.   

    这个不是写在FormSjbf的 
    是写在一个调用这窗体的别的窗体上的什么事件里的啊
    你要关闭FormSjbf 就直接写 close不成吗
    对了
    报什么错来着
      

  7.   

    project skglxtProject.exe raised exception class EAccessViolation with
    message 'Access violation at address 0045A8E5 in module 'ckglxtproject.exe'.
    Read of address FFFFFFFF'.Process stopped.Use Step or Run to continue.
      

  8.   

    其他的窗体用free就可以关闭,但formsjbf不行,没有任何反应
      

  9.   

    这个窗体是不是自动创建的 
     在工程->选项里面看看
    如果是自动创建的话
    FormSjbf:=TFormSjbf.Create(Application);应该就会错
      

  10.   

    to dh9450
    窗体的代码和你说的一样,请问如何解决?谢谢!
      

  11.   

    但其他的窗体也是FormSjbf:=TFormSjbf.Create(Application);这样创建的,但用free也能关闭,怎么formsjbf不行?
      

  12.   


    当然出错了,看看窗体的close 干了多少事情,你简单的Free能不出错吗?小小鸟
    你看懂了没有窗体的Close过程是在做什么?
      if fsModal in FFormState then              //首先判断是否是模式窗口
        ModalResult := mrCancel
      else
        if CloseQuery then        
        begin
          if FormStyle = fsMDIChild then         //判断是否是子窗体
            if biMinimize in BorderIcons then    //如果是子窗体上则判断是否有最小化按钮
              CloseAction := caMinimize else    
              CloseAction := caNone
          else
            CloseAction := caHide;
          DoClose(CloseAction);  //DoClose( if Assigned(FOnClose) then FOnClose
                                 //(Self, Action);)这段代码是判断是否定义了窗体的
                                 //OnClose事件,如果定义了则执行窗体的Onclose事件
                
          if CloseAction <> caNone then       //如果closeAction的状态不是caNone, 
                                              //(我们一般如果要关闭窗体会把窗体的
                                              //action := caFree)那么就判断是否是
                                              //程序的主窗体,如果是则结束application
                                         
            if Application.MainForm = Self then Application.Terminate
            else if CloseAction = caHide then Hide//如果是隐藏则隐藏
            else if CloseAction = caMinimize then WindowState := wsMinimized//如果
                                         //状态是最小化则最小化窗体
            else Release;                //否则就执行Release;
        end;这个过程对楼主的窗体最后执行的不过就是Release而已procedure TCustomForm.Release;
    begin
      PostMessage(Handle, CM_RELEASE, 0, 0);  //在窗体的Realse过程中是向窗体发送一个 
                                              //CM_RELEASE消息
    end;
    procedure TCustomForm.CMRelease;          //这个过程是窗体处理CMRelease消息的过程
    begin
      Free;                                   //在其中最后还是调用了Free;
    end;procedure TObject.Free;                   //Free事件中调用的则是窗体的析构过程
    begin
      if Self <> nil then
        Destroy;
    end;
    destructor TCustomForm.Destroy;
    begin
      if not (csDestroying in ComponentState) then GlobalNameSpace.BeginWrite;
      try
        if OldCreateOrder then DoDestroy;
        MergeMenu(False);
        if HandleAllocated then DestroyWindowHandle;
        Screen.RemoveForm(Self);
        FCanvas.Free;
        FIcon.Free;
        FreeAndNil(FActionLists);
        inherited Destroy;
      finally
        GlobalNameSpace.EndWrite;
      end;
    end;
      

  13.   

    function TCustomForm.CloseQuery: Boolean;//接着看这个CloseQuery函数,返回值是
                                             //boolean型;
    var
      I: Integer;
    begin
      if FormStyle = fsMDIForm then         //如果是母窗体则Result := false;
      begin
        Result := False;
        for I := 0 to MDIChildCount - 1 do    //循环看是否子窗体的CloseQuery为假的话 
                                              //则退出
          if not MDIChildren[I].CloseQuery then Exit;
      end;
      Result := True;                         //如果母窗体的所有子窗体的CloseQuery都
                                              //为真或者窗体本来就不是母窗体那么显然
                                              //窗体的CLoseQuery为真
      if Assigned(FOnCloseQuery) then FOnCloseQuery(Self, Result);//执行窗体的
                                               //OnCLoseQuery事件
    end;
      

  14.   

    我估计楼主的问题是:
    Application.CreateForm(TFormSjbf, FormSjbf);
    楼主可以看看自己的工程文件中是否有这一句,估计楼主的这个窗体是自动创建的,然后楼主又创建了一会。只要把这句话删了应该就没问题了。
    或者在Delphi7-project-option-form页签下Auto-create forms里面把FormSjbf去掉即可。
    不知道我分析的对不对