How can I get the button it is used to close a window

I use the following code to show a form and the Modalresult (mr) is allways 0.


var
  newform: THBMFrmE0;
  mr     : TModalResult;
begin
  newform := THBMFrmE0.Create(Self);
  newform.Caption := VK_EDatTxt;
  window.location.hash := 'subform';
  await(THBMFrmE0, newform.Load());
  newform.do_formcreate();
  try
    mr:= await(TModalResult, newform.Execute); // excute, wait for close
  finally
    newform.Free;
  end;
end;

Where can I found an example who shows how I can get the button the Window was closed with?

thanks for help
charly

Retested this here with the MultiForm demo where I changed the code in the main form to get the modalresult with:

procedure TForm1.WebButton1Click(Sender: TObject);
var
  newform: TForm2;
  mr: TModalResult;
begin
  newform := TForm2.Create(Self);
  newform.Caption := 'Child form';
  newform.Popup := WebRadioGroup1.ItemIndex <> 0;

  case WebRadioGroup1.ItemIndex of
  2: newform.Border := fbDialog;
  3: newform.Border := fbDialogSizeable;
  end;

  // used to manage Back button handling to close subform
  window.location.hash := 'subform';

  // load file HTML template + controls
  await(TForm2, newform.Load());

  // init control after loading
  newform.frm2Edit.Text := WebEdit1.Text;

  try
    // excute form and wait for close
    mr := await(TModalResult, newform.Execute);
    ShowMessage('Form 2 closed with new value:"'+newform.frm2Edit.Text+'"/'+mr.ToString);
    WebEdit1.Text := newform.frm2Edit.Text;
  finally
    newform.Free;
  end;
end;

and added 2 buttons on the child form with code:

procedure TForm2.WebButton1Click(Sender: TObject);
begin
  ModalResult := mrOK;
end;

procedure TForm2.WebButton3Click(Sender: TObject);
begin
  ModalResult := mrCancel;
end;

and in the dialog, I see as result either 1 or 2 depending on the OK or Cancel button clicked.

Hi

the assignment ModalResult:= mrxxx was missing.

With this it works well.

Thank you

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.