1. Rex Chivers
  2. PowerBuilder
  3. Tuesday, 7 January 2020 17:45 PM UTC

PB2017r3

Windows 10

I had an issue that I have not seen before.  I did not see anything in the questions and answers about it, I was wondering if anybody else has seen a similar issue.

I have a window opened as a sheet.  This window, when a user clicks in a field a response window is opened.  I am passing a structure with information into the response window when opening.  The user makes a selection on the response window and when closing it the selection is stored in the structure and passed back to the parent window.

In the parent window script I use isvalid on the powerobject being returned to test before continuing.  If the powerobject is valid then I put the structure being passed into a local structure and process it.  The same structure object is used when opening the response window, passing back to the parent, and loading the powerobject into the local structure. 

The response window has two command buttons ok and cancel, ok passes the structure back, and cancel close the response window and does not pass back the structure.

The issue comes when the user presses cancel and the window closes without returning a structure.  I expected the is valid check on the powerobject parm to recognize no structure had been returned and not process the remainder of the code.  However the powerobjectparm passed the isvalid test even though no object had been passed back.  

Watching in the debugger, we could see the response window close, and the code resume in the main window.  Watching to see why the isvalid did not handle as I expected I noted that the parent window grabbed another structure that had a totally different number of elements and changed the structure of my local variable declared structure to match it and loaded its data into the local declared structure.

I was a little shocked, thought I would at the very least have encountered an error that the two structure types did not match.  The 'phantom' structure had many more elements and different datatypes.  Has this behavior been noticed before ?  Is this a bug or do I need a better way to check the returning structure ?  Is this a feature that I have not been aware of that passing a structure as a powerobject could dynamically alter the structure it was being loaded into ???

Thanks for any advice or thoughts

Rex Chivers

Accepted Answer
Ricardo Jasso Accepted Answer Pending Moderation
  1. Tuesday, 7 January 2020 18:09 PM UTC
  2. PowerBuilder
  3. # Permalink

Rex,

I remember having this sort of issue a long time ago so I decided to add an additional variable to the structure, "cancel (true or false, 1 or 0)", and always return the structure for both Accept (cancel = 0) and Cancel (cancel = 1) buttons. I'm not sure why PB behaves that way when no structure is returned.

Regards,

Ricardo

 

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 7 January 2020 18:49 PM UTC
  2. PowerBuilder
  3. # 1

Instead of not doing a closewithreturn(), do a closewithreturn with a null / empty powerobject. That should do it.

 

Comment
There are no comments made yet.
Rex Chivers Accepted Answer Pending Moderation
  1. Tuesday, 7 January 2020 18:19 PM UTC
  2. PowerBuilder
  3. # 2

Thanks for the quick response Ricardo.  I did something similar, just passing back an empty structure for the cancel.  What really was odd was the way it altered the existing declared variable to fit the phantom structure.  It kept the same local variable name, but it changed all of the elements almost like it redeclared the local variable in the image of the phantom structure.

Your method of adding the field for cancel or continue is a good idea.  Thanks

Comment
  1. Ricardo Jasso
  2. Tuesday, 7 January 2020 18:42 PM UTC
The PowerObjectParm is part of the Message global variable which is used by the OpenWithParm and CloseWithReturn functions. After opening the response window and passing the structure, maybe PowerBuilder uses the Message object for other things during procesing of the reponse window until it is used again by CloseWithReturn. If Close is used instead of CloseWithReturn, PowerObjectParm will hold whatever PowerBuilder used it for earlier. Just my guess!
  1. Helpful
  1. Michael Kramer
  2. Wednesday, 8 January 2020 09:21 AM UTC
True, Message is global. Hence, risk of other code overwriting what your code just "inserted". If you want to know exactly what object is in Message.PowerObjectParm you may do ClassName(Message.PowerObjectParm). Remember to check IsValid before ClassName.
  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.