Closing Windows neatly

Post Reply
Ollie
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Closing Windows neatly

Post by Ollie »

I have a MDI application that opens different databases, say CLIENTS, SUPPLIERS and MANUFACTURERS.

I open each as a MDICHILD. (I use resources, so I have a borderless dialog the same size of the MDICHILD) (as taught to be my Antonio Linares and fwh\samples\TestMdi4.prg )

1. I want to prevent the user from opening the same table more than once, so I need to check before opening, if the window is defined - ISWINDOW() doesn't seem to be working - is it me? Is that correct way?

2.I've also tried checking if the table is already open - if it is, the user has opened the window before. (in this case I want to bring that window 'to the front'. I need a oWnd:Maximize() function like the oWnd:Restore() to do this?
(I tried: wndMain():oWndClient:aWnd[1]:setFocus() as suggested by James Bott on this forum - but this only brings the window to the front, not maximise it if it is restored.)


3. The problem with using the check in (2.) above, is that if the user doesn't press my "CLOSE NEATLY" button, I don't get to check that the last data was saved and that the databases get closed. (e.g. they press the 'X' on the window to close. ) Is the VALID clause where this needs to happen?

4. If the VALID clause is the correct place, do I put it on the (borderless) oDLG or on the oMDICHILDWnd ? All I can get it to do is to either close the whole app, or close without 'neatening up' first.
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
Ollie
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Post by Ollie »

I answered 2. myself: wndMain():oWndClient:aWnd[1]:MAXIMIZE()
(thanks to James Bott's 'bring window to the front')
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Ollie,

Better check if the table is already in use, and/or disable the menuitems and buttons to reopen a window meanwhile it is open
regards, saludos

Antonio Linares
www.fivetechsoft.com
Taavi
Posts: 77
Joined: Mon Nov 21, 2005 10:29 am

Re: Closing Windows neatly

Post by Taavi »

Ollie wrote:I have a MDI application that opens different databases, say CLIENTS, SUPPLIERS and MANUFACTURERS.

I open each as a MDICHILD. (I use resources, so I have a borderless dialog the same size of the MDICHILD) (as taught to be my Antonio Linares and fwh\samples\TestMdi4.prg )


1. I want to prevent the user from opening the same table more than once, so I need to check before opening, if the window is defined - ISWINDOW() doesn't seem to be working - is it me? Is that correct way?

Hi,
I use tis code to check if window with the same title is already opened:

for i := 1 to len(oWnd:oWndclient:aWnd)
if 'MDICHILD'$oWnd:oWndclient:aWnd:classname()
jcaption:=alltrim(oWnd:oWndclient:aWnd:cCaption)
if jcaption==alltrim(newcaption) //Alreadyhave MDI child with this name
oWnd:oWndclient:aWnd:Setfocus()
return


endif
endif
next
Ollie
Posts: 233
Joined: Sat Dec 30, 2006 6:10 am

Post by Ollie »

Thanks Taavi, I'll give it a try.

Antonio - how can I be sure that the databases are closed no matter how the user closes the screen.

E.g. If he presses the 'close' button, I check that the data is saved and that the tables are closed.

If he presses the Child 'X' to close or the Application 'X' to close - the checks don't get done.
Many thanks
Ollie.

Using:
xHarbour Compiler build 1.2.1 (SimpLex) (Rev. 6406)
Borland C++ 5.5.1
FWH 9.04 (2009 Apr)
User avatar
dbzap
Posts: 189
Joined: Mon Nov 07, 2005 7:36 pm
Location: Chile
Contact:

Post by dbzap »

I use a static variable then when i come in i set the var in "9999" and later if try to in one more time i see if the var is set to NIL or <> NIL
then when i finish restart de var to NIL .....
that's my way !!
Julio Gonzalez V.
RANDOM S.A.
SISTEMICA S.A.
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

I have a same problem

I use this code:

Code: Select all

#command OPEN <(db)>                                                    ;
             [VIA <rdd>]                                                ;
             [ALIAS <a>]                                                ;
             [<new: NEW>]                                               ;
             [<ex: EXCLUSIVE>]                                          ;
             [<sh: SHARED>]                                             ;
             [<ro: READONLY>]                                           ;
             [INDEX <(index1)> [, <(indexn)>]]                          ;
       => if Select( <(db)> )==0                                        ;
         ;      dbNetUseArea( <.new.>, <rdd>, <(db)>, <(a)>, if(<.sh.> .or. <.ex.>, !<.ex.>, NIL), <.ro.>, 0 )[; dbSetIndex( <(db)> )];
         ;else                                                          ;
         ;   dbSelectArea( <(db)> )                                     ;
         ;endif
In if Select( <(db)> ) you pass the table name and if is not in memory open or just select the open table.

Code: Select all

...
if Select( "clients" )==0
   use CLIENTS shared new index ...
else
   dbSelectArea( "clients" )
endif
...
Post Reply