xsharp.eu • Closing Datawindow method
Page 1 of 1

Closing Datawindow method

Posted: Mon Jan 10, 2022 8:16 pm
by OhioJoe
What DataWindow method is invoked when the user closes the window by checking the "X" in the upper-right?
Trying to insert an "Are you sure?" confirmation in some of the data-entry windows.
Thanks everyone.

Closing Datawindow method

Posted: Mon Jan 10, 2022 9:23 pm
by Jamal
Joe,

VO calls the QueryClose method. See the Windows Properties dialog, then click the dotted button to generate the QueryClose event call such as:

Code: Select all

method QueryClose(oEvent) class YourWindow
	local lAllowClose as logic
	lAllowClose := super:QueryClose(oEvent)
	//Put your changes here  
	return lAllowClose

Set lAllowClose to TRUE to close the window.

Jamal

Closing Datawindow method

Posted: Tue Jan 11, 2022 6:42 pm
by OhioJoe
Thank you, Jamal.
Did this. Didn't work.
I inserted a pop-up text box in place of "// Put your changes here". Nothing. Am I missing something?
Here's the problem I'm trying to fix: I've been getting complaints from some users (who in turn complain to their higher-ups) that their data-entry isn't saving. That is almost certainly because they're closing the window by clicking the "X" rather than by hitting our "Save and Exit" button. So they need a reminder.

Closing Datawindow method

Posted: Tue Jan 11, 2022 7:05 pm
by wriedmann
Hi Joe,
AFAIK closing with the X ignores the QueryClose() method.
I'm disabling that X with:

Code: Select all

method EnableSysClose( lEnable as logic ) as void pascal class GeneralDataWindow
if lEnable == false
	EnableMenuItem( GetSystemMenu( self:Handle(), FALSE ), SC_CLOSE , _or( MF_BYCOMMAND, MF_GRAYED ) )
else
	EnableMenuItem( GetSystemMenu( self:Handle(), FALSE ), SC_CLOSE , _or( MF_BYCOMMAND, MF_ENABLED ) )
endif
return
Wolfgang

Closing Datawindow method

Posted: Tue Jan 11, 2022 8:08 pm
by GlenT
HI,

Here's a snippet from one of my datawindows that asks a question if on saved:

METHOD QueryClose( oCE ) CLASS bTakeoffWin
LOCAL nRtn AS DWORD
LOCAL lAllowClose AS LOGIC
LOCAL nLen AS DWORD
LOCAL nCounter AS DWORD
LOCAL oCol AS bDataColumn
LOCAL nX AS LONGINT
LOCAL nY AS LONGINT
LOCAL nH AS LONGINT
LOCAL nW AS LONGINT
LOCAL oSize AS Dimension
LOCAL oOrigin AS Point

lAllowClose := SUPER:QueryClose( oCE )
IF lAllowClose
IF SELF:lNeedSave
IF !SELF:lIsClosing
SELF:lIsClosing := TRUE
nRtn := PCE_YESNOCANCELBOX( SELF, 'Takeoff', 'Takeoff has been changed, save changes?' )
DO CASE
CASE nRtn == BOXREPLYYES
lAllowClose := SELF:SaveData()
CASE nRtn == BOXREPLYNO
lAllowClose := TRUE
SELF:lNeedSave := FALSE
CASE nRtn == BOXREPLYCANCEL
lAllowClose := FALSE
ENDCASE
SELF:lIsClosing := FALSE
ELSE
lAllowClose := FALSE
ENDIF
ELSE
lAllowClose := TRUE
ENDIF
IF lAllowClose
SELF:lInit := TRUE
ENDIF
IF lAllowClose
.......


PCE_YESNOCANCELBOX is just a wrapper around the textbox:

FUNCTION PCE_YESNOCANCELBOX( oObj AS OBJECT, cTitle AS STRING, cQuestion AS STRING ) AS DWORD

LOCAL nRtn AS DWORD
LOCAL oTB AS textbox

oTB := textbox{ oObj, cTitle ,cQuestion }
oTB:Type := BOXICONQUESTIONMARK + BUTTONYESNOCANCEL
nRtn := ( oTB:Show() )
oTB:Destroy()
RETURN nRtn

Closing Datawindow method

Posted: Tue Jan 11, 2022 8:17 pm
by ic2
Hello Wolfgang, Joe,
AFAIK closing with the X ignores the QueryClose() method.
In VO?

I use the QueryClose all over. And it is is certainly called when I close the datawindow with the "X". Here I have a method CheckChanged using a variable lChanged which is set to True in the EditChange. If true is passed to CheckChanged my program asks if changes should be saved. On Yes, my RecordSave method is called. Both are methods from my DataWindow subclas, the latter is a general way to save control contents in the underlying DBF.

Joe, did you probably add the method to a window being part of a tab window? That won't work, the QueryClose should be of the Tab window (and you can call queryClose methods of the datawindows within that tabwindow from there).

You might also want to read Jamal's question way back, in 2004, and Chris Pyrga's' replies:

https://groups.google.com/g/comp.lang.c ... TLAtIk2GIJ

Dick

Closing Datawindow method

Posted: Tue Jan 11, 2022 8:38 pm
by Jamal
Joe,

It works for me! Take a look at the attached sample AEF.

[The extension aef has been deactivated and can no longer be displayed.]

[The extension mp4 has been deactivated and can no longer be displayed.]

If you still have an issue, post a sample AEF that shows the problem.

Jamal
OhioJoe wrote:Thank you, Jamal.
Did this. Didn't work.
I inserted a pop-up text box in place of "// Put your changes here". Nothing. Am I missing something?
Here's the problem I'm trying to fix: I've been getting complaints from some users (who in turn complain to their higher-ups) that their data-entry isn't saving. That is almost certainly because they're closing the window by clicking the "X" rather than by hitting our "Save and Exit" button. So they need a reminder.

Closing Datawindow method

Posted: Tue Jan 11, 2022 8:54 pm
by OhioJoe
thank you, everyone.
Jamal, Dick: You're right. There's no reason this shouldn't work. But after reading that old post, I think the problem might be in the Dispatch() method of the inherited class.
I'll get to work on these solutions and report back.