ModelResult问题

我在BCB中写:

void __fastcall TForm1::BitBtn1Click(TObject *Sender)

{

      if(Form2->ShowModel()==mrok)

           //检查发现this->ModelResult=2; (mrcancel=2)

}

void __fastcall TForm2::BitBtn1Click(TObject *Sender)

{

       ModelResult=mrok;(mrok实际值是1)

      Close();

}

 

查看VCL源码才发现:

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;

 

想了想,

...

      if FormStyle = fsMDIChild then
        if biMinimize in BorderIcons then
          CloseAction := caMinimize else
          CloseAction := caNone
      else
        CloseAction := caHide;                               //模式窗体CloseAction := caHide,我调用Close()其实就是执行了Hide(),并没有释放窗体

....

        if Application.MainForm = Self then Application.Terminate
        else if CloseAction = caHide then Hide                                                          //Hide
        else if CloseAction = caMinimize then WindowState := wsMinimized
        else Release;

 

最后改成这样了

void __fastcall TForm2::BitBtn1Click(TObject *Sender)

{

       ModelResult=mrok;(mrok实际值是1)

      Hide();

}

你可能感兴趣的:(ModelResult问题)