1. Tracy Lamb
  2. PowerBuilder
  3. Saturday, 23 July 2022 23:21 PM UTC

Hi all,

In my main app I have a "Navigator".  The user double-clicks on a window name to open it.  One of the windows is "Status Tracking". 

In some windows, the user can double-click on a particular dw row to open another window.  If I double-click from say, the Lab Folder, the Lab Folder opens Status Tracking and sends in a PowerObjectParm consisting of several arrays.  Status Tracking checks for a PowerObjectParm, and if it's not null it processes accordingly (basically automatic retrieve).  If a PowerObjectParm is not passed in, Status Tracking should open in Query mode.

This is working fine when when I open Status Tracking from other windows.  But, when I open Status Tracking from the navigator (ie, no PowerObjectParm sent in) I'm getting a Null Object Reference, line 23 of pfc_postopen event.

Here's how I open Status Tracking from the Lab Folder:

istr_parms.long_arg[1] = ll_salesorder
istr_parms.long_arg[2] = ll_workorder
istr_parms.string_arg[1] = "WO"
OpenSheetWIthParm(lw_sheet, istr_parms, "w_md_status_tracking", w_benchtop_frame, 0, Layered!)

Here's  the Status Tracking pfc_postopen event :

// Save parameters that may have been sent in
if NOT IsNull(Message.PowerObjectParm) then
	istr_parms = Message.PowerobjectParm
	is_retrieval_type = istr_parms.string_arg[1]
	il_salesorder = istr_parms.long_arg[1]
	if UpperBound(istr_parms.long_arg) > 1 then
		il_workorder = istr_parms.long_arg[2]
	end if
	dw_1.Retrieve(il_salesorder)
	if is_retrieval_type ="WO" then
		rb_workorder.Checked = TRUE
		//Scroll to the workorder that was sent in
		// Find this workorder in the list...
		ls_find = string( il_workorder )
		ll_ThisRow = dw_2.inv_find.of_find( "id", ls_find, 1, dw_2.RowCount() )
		if ll_ThisRow > 0 then
			dw_2.ScrollToRow( ll_ThisRow )
			dw_2.SelectRow( 0, False )
			dw_2.SelectRow( ll_ThisRow, True )
		end if
	end if
end if

I'm getting a NULL Object Reference line 23 (is_retrieval_type) when I open Status Tracking from the Navigator.  The Message.PowerObjectParm should be null as I opened the window without any parameters and this whole IF clause should be skipped.  Maybe the Message.PowerObjectParm is not Null and is a hangover from previous calls?  In the debugger, istr_parms isn't even the right structure. How can I check to see if the PowerObjectParm is of the class/type str_parms?

~~~Tracy

 

Accepted Answer
John Fauss Accepted Answer Pending Moderation
  1. Sunday, 24 July 2022 02:06 AM UTC
  2. PowerBuilder
  3. # Permalink

Hi, Tracy -

To build on Chris' reply...

The commercial app I help support is also PFC-based. Since the default Message object is has global scope, any code, anywhere can muck with it. Therefore, whenever a window is opened via OpenWithParm or OpenSheetWithParm, we always check it in the opened window's pfc_PreOpen event (which, as you know, is triggered in the base window's Open event script).

Even then, we perform a series of nested If-statements to verify the contents. Something like:

// pfc_PreOpen event.
s_parms lstr_parms

If IsValid(Message.PowerObjectParm) Then
   // Was a generic parameters structure passed in?
   If Message.PowerObjectParm.Classname() = "s_parms" Then
      lstr_parms = Message.PowerObjectParm
      // Are the parameters values expected by this window present?
      If UpperBound(lstr_parms.s_val[]) >= 2 Then
         // Two string values have been supplied...
            .
            .
            .
      Else
         MessageBox( ... )
         Close(this)
         Return
      End If
      // A long value is also expected...
      If UpperBound(lstr_parms.l_val >= 1 Then
         // Same song, 2nd verse
            .
            .
            .
      Else
         MessageBox( ... )
         Close(this)
         Return
      End
      .
      .
      .
   Else
      MessageBox("Dude!","The expected parameters structure was not supplied!")
      Close(this)
      Return
   End If
Else
   MessageBox("Ruh-roh, Rorge...","Astro says no valid object was passed to this window!)
   Close(this)
   Return
End If

Regards, John

Comment
  1. Chris Pollach @Appeon
  2. Monday, 25 July 2022 13:46 PM UTC
Hi Tracy;

Another good point from John's code example ... Only use the ISVALID () command to test for valid object pointers. The IsNull() command you mentioned in your initial post is *not* for pointer validation. It's designed for testing data values of type NULL. You can have a non-null object pointer but in reality, that positive memory address may no longer be valid. So the Isnull() would be FALSE making your code "think" that the object pointer was OK whereas in reality it might not be. The IsValid() command though will verify the memory address properly. Food for thought. HTH

Regards .. Chris
  1. Helpful 1
  1. Olan Knight
  2. Tuesday, 26 July 2022 21:08 PM UTC
>>> Only use the ISVALID () command to test for valid object pointers.

I learn something new every day! Thanks, guys!
  1. Helpful
There are no comments made yet.
Tracy Lamb Accepted Answer Pending Moderation
  1. Tuesday, 26 July 2022 23:41 PM UTC
  2. PowerBuilder
  3. # 1

Thanks all for your replies and comments.  I moved the code to the Open event, and changed IsNull is IsValid.  Works like a charm!  Like Olan, I learn something new every day!

Comment
There are no comments made yet.
Olan Knight Accepted Answer Pending Moderation
  1. Monday, 25 July 2022 21:50 PM UTC
  2. PowerBuilder
  3. # 2

Tracey -

   Everone does it, probably including me, but I really do not like IN-LINE compound code. Try this and see if it works. I've seen cases where the in-line desconstruction fails while the separate line by line code succeeds. And remember, in-line code is actally slightly less efficient than line by line code since it has to be deconstructed before being processed.



powerobject   lpo_1

lpo_1 = Message.PowerObject

IF (IsNull (lpo_1)) THEN

.....

END IF

Comment
  1. Tracy Lamb
  2. Wednesday, 27 July 2022 00:23 AM UTC
I agree with you... but I do this same thing everywhere else. Sorry excuse, I know, but at least I'm consistent!
  1. Helpful
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Saturday, 23 July 2022 23:50 PM UTC
  2. PowerBuilder
  3. # 3

Hi Tracy;

  FYI: the only two places where PowerObjectParm is valid in an OpenWithParm command is either in the Open event of a Window or a Constructor event of a Visual control. After that, the POP can be reused for something else by other processing. So processing the POP in a "Post Open" event may definitely not be reliable.

Regards ... Chris

Comment
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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.