Re: Break into the Form Close event
From: Edgar Rodriguez (edgarrod_at_programmer.net)
Date: 10/09/03
- Next message: Alessandro: "simple question"
- Previous message: Ian Kirk: "Re: simple question"
- In reply to: Pat Mc: "Break into the Form Close event"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 09 Oct 2003 08:08:59 -0500
Use onCloseQuery event instead.
Edgar Rodriguez
edgarrod@programmer.net
On Thu, 09 Oct 2003 12:11:44 +1000, Pat Mc
<patabc@NOSPAMozemail.com.au> wrote:
>Hi,
>
>Got a form with a database table
>
>Got an OK button that checks certain fields before saving the table.
>It will not let you save the record unless these fileds are filled in.
>This works well.
>
>I have a procedure on the form CLOSE event and this checks if any
>changes are made and asks you if you want to saved them. If I say YES
>it checks if certain fields are filled in but then closes the FORM (
>it does not stop and set the focus to the field that needs filling in)
>
>Question is how can I stop the FORM from closing from the FORM Close
>event (I know that the Form Close event's job is to close the form,
>but how can I break into this event)?
>
>Should I design my form better?
>Note: I did not design the Form Close procedure below, it was a code
>snippet I had.
>
>Thanks for any replies,
>Pat
>
>-----------------------------------------------------------------------------------------
>procedure TMyForm.btnOKClick(Sender: TObject);
>begin
>
> if CheckFields=1 then
> begin ShowMessage(' Surname field is blank.. ');
> editSurname.SetFocus; exit; end
> else if CheckFields=2 then.........
>
>end
>-----------------------------------------------------------------------------------------
>procedure TMyform.FormClose(Sender: TObject;
> var Action: TCloseAction);
>begin
> if MyTable.State in [dsInsert, dsEdit] then
> begin
> if (MyTable.State = dsInsert) and (MyTable.Modified <> true) then
> begin
> btnCancelClick(sender); Action := caFree;
> end
> else
> case Application.MessageBox(PChar('Do you want to save
>changes?'),
> PChar(Application.Title), mb_YESNOCANCEL + mb_DefButton1 +
>mb_IconWarning)
> of
> IDYES: begin btnOKClick(sender); Action := caFree; end;
> IDNO: begin btnCancelClick(sender); Action := caFree; end;
> IDCANCEL: Action := caNone;
> end;
> end
> else Action := caFree;
>end;
>-----------------------------------------------------------------------------------------
- Next message: Alessandro: "simple question"
- Previous message: Ian Kirk: "Re: simple question"
- In reply to: Pat Mc: "Break into the Form Close event"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|