Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Asking the user for OnCloseQuery response
Wed, Mar 13 2019 3:05 PMPermanent Link

Matthew Jones

I just realised that the normal way to handle OnCloseQuery is to pop up a dialog and ask the user if they want to close. But in EWB, isn't that going to not-block, and thus the call will return before the dialog is all complete? What's the way to make this work?

--

Matthew Jones
Thu, Mar 14 2019 1:01 AMPermanent Link

ooptimum

I do it like this:

var FormCloseFlag: Boolean = False; // actually a form field

function TMyform.CloseQueryHandler(Sender: TObject): Boolean;
begin
 if FormCloseFlag then
   Result := True
 else begin
   MessageDlg('Are you sure ... ?', 'Please confirm', mtConfirmation, [mbYes, mbNo], mbNo, CheckClose, True);
   Result := False; // Don't close yet
 end;
end;

procedure TMyform.CheckClose(DlgResult: TModalResult);
begin
 if DlgResult = mrYes then begin
   FormCloseFlag := True;
   Close;
 end;
end;
Thu, Mar 14 2019 4:33 AMPermanent Link

Matthew Jones

ooptimum wrote:

> I do it like this:
>
> var FormCloseFlag: Boolean = False; // actually a form field
>
> ...


A nice solution - unfortunately my application is sort of stateless, so I'd have to remember where the user wanted to go too. What I've done for the moment is just show a red label telling them to save or discard first, and abort the action with an exception that I ignore. Basically I lock them in the form using a flag as you suggest that indicates if there is something to save or not.

--

Matthew Jones
Thu, Mar 14 2019 5:37 AMPermanent Link

ooptimum

<< What I've done for the moment is just show a red label telling them to save or discard first, and abort the action with an exception that I ignore. Basically I lock them in the form using a flag as you suggest that indicates if there is something to save or not. >>

I think there is a simpler solution without imploying exceptions, if I understand you right.

function TMyform.CloseQueryHandler(Sender: TObject): Boolean;
begin
if WeHaveSomethingToSave then begin
  // Inform a user here that data should be saved or discarded first
  Result := False; // don't allow form to close
else
  Result := True;
end;
Thu, Mar 14 2019 6:05 AMPermanent Link

Matthew Jones

ooptimum wrote:

> << What I've done for the moment is just show a red label telling them to save or discard first, and abort the action with an exception that I ignore. Basically I lock them in the form using a flag as you suggest that indicates if there is something to save or not. >>
>
> I think there is a simpler solution without imploying exceptions, if I understand you right.
>
> function TMyform.CloseQueryHandler(Sender: TObject): Boolean;
> begin
>  if WeHaveSomethingToSave then begin
>    // Inform a user here that data should be saved or discarded first
>    Result := False; // don't allow form to close
>  else
>    Result := True;
> end;

That's basically what I'm doing, except that the user has clicked a button so do something else, and the form won't be visible any more if that continues. Therefore I have to use an exception to stop that happening.

--

Matthew Jones
Thu, Mar 14 2019 6:06 AMPermanent Link

Matthew Jones

I should say that the form is not modal - hence the issue. I pondered going modal, but I don't think that would look good.


--

Matthew Jones
Image