1. Olan Knight
  2. PowerBuilder
  3. Monday, 14 March 2022 22:26 PM UTC

UPDATE: 

   FYI:  This works:

boolean        lb_valid
string           ls_column

lb_valid = IsNull (adw_object)
IF (NOT (lb_valid)) THEN RETURN                    // <--- the lb_valid value is FALSE at this point, as it should be.

lb_valid = IsValid (adw_object)
IF (NOT (lb_valid)) THEN RETURN


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

PowerBuilder 2019R3, b2703
Windows 10, 64 bit platform


This bit of ancient code is failing because the return value of the ISNULL function is TRUE instead of FALSE, as it shoudl be.
Note that PowerBuilder's IDE in debug mode recognizes that the object is NULL. I hovered the mouse over the variable before taking the screen shot.

Is there something I can do to correct this?




Thanks!

 

Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Monday, 14 March 2022 22:53 PM UTC
  2. PowerBuilder
  3. # 1

Hi Olan;

   If this is reproducible, please create a support ticket.

However, the developer should have used the IsValid() command instead in the first place.

Regards ... Chris

Comment
  1. Olan Knight
  2. Tuesday, 15 March 2022 16:43 PM UTC
It has been my experience that the ISNULL command always comes first because otherwise, when you run an ISVALID() on a null object, yoour code abends.



Could be that it's different in 2019...
  1. Helpful
  1. Chris Pollach @Appeon
  2. Tuesday, 15 March 2022 17:55 PM UTC
Hi Olan ... The IsValid() command has never behaved that way (at least AFAIK). I have been using that command in my STD frameworks for 3 decades now with no issues. To me, the IsNull() command is only for "Standard Data Types".
  1. Helpful
  1. Roland Smith
  2. Thursday, 17 March 2022 13:33 PM UTC
I've always done it like Chris, IsNull for standard types and IsValid for objects. I looked at the help for IsNull and it appears that it should work on objects:



If the variable is of a reference type (a type derived from the PowerObject base class), IsNull returns true if the variable has not been initialized by assigning an instantiated object to it.
  1. Helpful
There are no comments made yet.
Benjamin Gaesslein Accepted Answer Pending Moderation
  1. Thursday, 17 March 2022 10:58 AM UTC
  2. PowerBuilder
  3. # 2

Hi Olan,

I'm not sure I understand your exact problem. You say this doesn't work as expected:

IF (isnull(adw_object)) then RETURN

While this does:

lb_valid = IsNull (adw_object)
IF (NOT (lb_valid)) THEN RETURN                    // <--- the lb_valid value is FALSE at this point, as it should be.

Yet your "This works" snippets is doing the exact opposite of what the original code did. #1 will return if adw_object is null, #2 will return if adw_object is *not* null.

 

Comment
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Friday, 18 March 2022 12:10 PM UTC
  2. PowerBuilder
  3. # 3

Hi.

I see your comments about using isnull for standard datatypes and isvalid for objects. And I agree. But I will mention that code like the following can be found in PFC's:

// Validate the dwo reference.
IF IsNull(adwo_obj) OR NOT IsValid(adwo_obj) THEN	 
	Return -1
END IF 

In that case, is it wrong to run both checks? Should this change to:

// Validate the dwo reference.
IF NOT IsValid(adwo_obj) THEN	 
	Return -1
END IF 

It's just a question. I'm interested if the original code needs to be fixed!

Thanks.

Andreas.

Comment
  1. Olan Knight
  2. Saturday, 19 March 2022 23:14 PM UTC
What Benjamin said. And what I said earlier.

Failure to test for ISNULL before testing for ISVALID can lead to an application abend.
  1. Helpful
  1. Olan Knight
  2. Saturday, 19 March 2022 23:18 PM UTC
Andreas -

The PFC has worked well for decades. But then again, the inline ISNULL worked for decades as well; but in my case in at least one example it no longer works. See the image for proof. I am in the process of replacing in-line code with separate ISNULL and ISVALID checks as I run into issues and as I see instances where inline code exists.



Maybe I should start going through my version of the PFC..... it won't hurt and might prevent failures in the future. But being utterly swamped, I'll probably just leave everything alone and fix it only if the abend occurs elsewhere. :/

  1. Helpful
  1. Chris Pollach @Appeon
  2. Saturday, 19 March 2022 23:24 PM UTC
Darn...using PB since 1989 & IsValid has never let me down PB app crash wise. ;-)
  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.