1. Gastón Clara
  2. PowerBuilder
  3. Friday, 11 December 2020 15:26 PM UTC

Hi, 

I need to implement Log-off functionality in my application and for this reason I would like to close all opened windows. The use of GetFirs and GetNext Sheets is not enough as we open some windows but not as sheets. 

Is there any way to get all the windows(or objects) at a certain point of time so I can evaluate the classname in order to detect if it's a window and close it?

Any other idea would be welcome!

 

Thanks.

Gastón Clara Accepted Answer Pending Moderation
  1. Friday, 12 March 2021 14:47 PM UTC
  2. PowerBuilder
  3. # 1

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 11 December 2020 19:12 PM UTC
  2. PowerBuilder
  3. # 2

Hi Gastón;

   This seems like an easy thing to do when you first think about it but it is actually a very complex issue behind the scenes. Also, not all Apps are MDI and even if they are - there could also be both Child and Pop-up windows open to consider as well. Then you have another important issue ... closing the windows in the exact reverse order that they were opened. I found out a long ago that closing them in a random order can lead to App crashes. Apps also need to handle Window closes in a nice logical way too for the CloseQuery events so that business end-of-transaction states are upheld. Another reason for closing window classes in the exact reverse order.

   I solved these challenges a few decades ago in my STD Framework by creating a Window Manager service. This service (which is completely transparent to any PB App) handles the tracking of opening and closing windows. It is called when any window activity is performed and also handles the Close All Windows functionality. For example:

The Window Manager service also keeps track of all MS-Window resources that the Open Window class consumes including memory and GDI resources for all of its controls. It also tracks how many times any given window is activated / deactivated, number of key stokes it receives, O/S messages and the state of the Window and its controls on disposition. For example:

   If you are interested, the framework that I use for all my App development (and many PB customers do as well) - it is free and open sourced under an Apache 2.0 licensing model since 1995 (and written in 1992 before the PFC). You can read about the latest release and download it from this posting:   http://chrispollach.blogspot.com/2020/08/2020r2.html

  If you download the framework or better yet, it's example OrderEntry Demo App - have a look at the Window  Controller object class "wn_controller_master" in the STD_FC_PB_Base.pbl and then look at the following method implementations: of_get_all_tracked_windows, of_register_tracked_window and of_unregister_tracked_window. For the Close All functionality, have a look at the Window Controller class "wn_controller_master" in the STD_FC_PB_Base.pbl library and it's "oe_close_all" event.

 This code will show you how its done (or at least how I did it). You are welcome to use the framework or assimilate whatever code bits and pieces that you need into your own implementation. The above code is now in its 3rd iteration since I wrote it originally circa 1998 and the last major revision was in 2011 (with small tweaks after that). It has stood up to all the Sybase, SAP & Appeon releases of PB - including PowerServer Web & Mobile Apps (as translated to jScript). It currently works great with the new PowerClient feature based Apps found in the PB 2019 R3 beta that I have tested thus far. I hope to be testing this code soon too in the upcoming PB / PowerServer 2021 releases coming in 2021 as well.  ;-)

HTH

Regards ... Chris

Comment
  1. Gastón Clara
  2. Monday, 14 December 2020 15:42 PM UTC
Thank you for yout answer Chris.

Will take a look at it. Hope it helps !!!
  1. Helpful
  1. Gastón Clara
  2. Friday, 12 March 2021 14:53 PM UTC
Hi @Chris, I've implemented a window manager, as you suggested, for closing all opened windows. It worked fine since I found a problem where after closing all windows the system remains in an unstable status doing strange things. For example, menu for the MDI window starts to display characters in Chinese, and some strange characters.

I've tried just to execute a Halt after closing all windows and dub, and the debugger remains active just after executing Halt command. Weird !



After lot of research I found that the reason about this unstable status after is that we have that MDI, that opens a sheet, that opens a response and this response opens another response. If I run the process to close all windows is after closing all those windows that the system remains unstable or running after the the halt. I changed the window type of the second response to main and..... it works without any problem. The system remains stable or completely closes the app after the halt.

Do you have any idea on that? Is there any restriction that you can't or you shouldn't open a response from another response?



Thank you in advance for your help !

  1. Helpful
  1. Chris Pollach @Appeon
  2. Friday, 12 March 2021 19:06 PM UTC
Hi Gastón;

That was a restriction in very early PB versions (1.0 - 3.0). Having a Response open from Response was tricky (or impossible) in those PB generations but, PowerSoft eventually cleaned that issue up by the PB 5.0 days (AFAIK or remember).

However even in newer PB releases, closing *multiple* Response (ie R => R => Messagebox ) windows in the *exact* same *reverse* order was the key to making sure that your App did not "hang". That's one of the reasons that I created my framework's Window Manager - so that the Window closings would be in the correct reverse order. Once I had that service working (circa 1998), I never had an App closure issue from that point onward. Even today in PB2021 beta).

PS: My framework does not use any MessageBox() commands either that could cause another Response window to open during an App closing process. ;-)

Regards ... Chris
  1. Helpful
There are no comments made yet.
Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Friday, 11 December 2020 15:39 PM UTC
  2. PowerBuilder
  3. # 3

Hi Gastón,

 

Perhaps you may find a good example of what you are looking for here: https://github.com/Appeon/PowerBuilder-RibbonBar-Example

 

 

Regards,

Comment
  1. Miguel Leeuwe
  2. Wednesday, 16 December 2020 10:12 AM UTC
Good points Chris, but in this case, I assume Gast'on wants to close the application too since he mentions "I need to implement Log-off functionality".
  1. Helpful
  1. David Peace (Powersoft)
  2. Wednesday, 16 December 2020 14:41 PM UTC
Indeed, sometimes it does not need over thinking ;-)
  1. Helpful
  1. Chris Pollach @Appeon
  2. Wednesday, 16 December 2020 19:53 PM UTC
Been there, done that, got burned many times on a HALT Close and lost datum ... but, what the heck - go for it. ;-)
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.