1. Dan Black
  2. PowerBuilder
  3. Friday, 15 May 2020 18:42 PM UTC

Hey,

Here's some background. I am trying to add a 'restore layout' feature so that when the user logs in their active sheets from the previous session restore to their position. I've got it working pretty nicely but I've ran up against a snag.

1. The layout is saved by saving the w_sheet.classname() and the position values to a string.

2. The layout is restored by reading the string and using OpenSheet like this:

Window w_sheet
OpenSheet (w_sheet, 'w_that_is_cool', w_main, ing_window_menu, Original!)

but afterwards any calls to IsValid(w_that_is_cool) return FALSE. I assume this is because w_sheet was of type Window when OpenSheet was called, but that doesn't really help me.

This is contrasted with how windows are usually opened in our program with

OpenSheet (w_that_is_cool, w_main, ing_window_menu, Original!)

afterwards IsValid(w_that_id_cool) returns TRUE as expected.

Does anyone know have any ideas how I can dynamically open windows but also have them be recognized by IsValid?

Thanks,

Dan

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Friday, 15 May 2020 19:34 PM UTC
  2. PowerBuilder
  3. # Permalink

Greetings, Dan - 

The problem is your attempt to reference the "w_that_is_cool" global variable without it ever having been assigned a value.

Background: If you Edit Source on a window, near the top you'll see a line similar to this:

global w_that_is_cool w_that_is_cool

Translated: Create a global reference variable named "w_that_is_cool" of type w_that_is_cool.

So w_that_is_cool is BOTH an object type and a global variable. When you invoke OpenSheet like this:

OpenSheet(w_that_is_cool, ...

That first argument is the reference variable that receives the reference to the instantiated object...the global variable named w_that_is_cool. When you invoke OpenSheet like this:

window lw_window
OpenSheet(lw_window, 'w_that_is_cool', ...

The global var w_that_is_cool does not get assigned like it did in the preceding example, so the global var does not contain a valid object reference.

If you really need to perform an IsValid() test while opening sheet windows "generically", you need to instead search all of the MDI sheets via GetFirstSheet(), GetNextSheet(), use IsValid() to ensure each (window) object is valid, then uss ClassName() to see if the window is of type "w_that_is_cool".

HTH. Regards, John

Comment
  1. Dan Black
  2. Friday, 15 May 2020 21:00 PM UTC
Thanks John,

I didn't realize the global variable stuff, it makes sense as you describe it. It would be handy if



OpenSheet(lw_window, 'w_that_is_cool', ...



did setup the global variable ;)



I think I came to the same conclusion: I'd have to write my own IsValid function that calls IsValid but also looks at all the open sheets to see if they are valid.

  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Friday, 15 May 2020 19:54 PM UTC
  2. PowerBuilder
  3. # 1

Hi Dan;

   I would  ...

1) Change the OpenSheet() to an OpenSheetWithParm command to pass an indicator (ie Restore=Y/N)

2) In the open of the sheet, use the ClassName() command of the sheet for a match with names that you have saved. If a match is found, perform the "location restore" on or "just after" the open (ie: PostOpen event). Save the Restore = Y/N request status in an instance variable.

3) On the close of the sheet, if the instance variable Restore = Y ...  then, save the X,Y,W,H values.

  FWIW: The above design should totally encapsulate the process and make the coding easier (well, IMHO). Also note that the above design would also work for any Window Type or its open usage (ie: Main, vs Sheet, Dockable, etc).  ;-)

HTH

Regards ... Chris

 

 

 

Comment
  1. Dan Black
  2. Friday, 15 May 2020 20:53 PM UTC
Thanks Chris, I like that the restoration of location/values is handled the window(s) (as you said, it's encapsulated).
  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.