Link to home
Start Free TrialLog in
Avatar of firekiller15
firekiller15

asked on

How to auto close the form after ok button is pressed.

Delphi
i use form1 to insert data. When i click ok a message box prompted to tell me my data has been inserted .
How can i auto close the form1 after i click ok on the message box.
ASKER CERTIFIED SOLUTION
Avatar of Geert G
Geert G
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
procedure TForm1.Button6Click(Sender: TObject);
begin
  ShowMessage('message text');
  Close;
end;

or if it is modalform:

procedure TForm1.Button6Click(Sender: TObject);
begin
  ShowMessage('message text');
  ModalResult := mrOk;
end;


ziolko.
damn geert you were faster... look at Q ids:)

ziolko.
ziolko
hey, you had to type 2 solutions :)
Avatar of firekiller15
firekiller15

ASKER

If i want to use messageDlg how?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ziolko >>
you could even mix it


case MessageDlg('Do you like the inserted data ?', mtConfirmation, [mbYes, mbNo], 0) of
  mrYes: case MessageDlg('Really ?', mtConfirmation, [mbYes, mbNo], 0) of
    mrYes: ; // Ok
    mrNo: ShowMessage('Too bad, the data was inserted anyway !');
  end;
  mrNo: ShowMessage('Alter it then ... ');
end;

Open in new window

yeah I know I can mix it even with:
MessageBox(Handle, 'Message', 'Message caption', MB_OK or MB_ICONINFORMATION);

but as I understand firekiller15 just wanted use MessageDlg instead of ShowMessage

ziolko.
I think if we are talking about MDI Forms,
that is still missing

procedure MyMDIForm.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
       Action := caFree;
end;
ah, but didn't we forget this too then ?


PostMessage(Handle, WM_CLOSE, 0, 0);

Open in new window