1. Troy Cowan
  2. PowerBuilder
  3. Wednesday, 25 May 2022 14:07 PM UTC

I have a situation where after a yield(), sometimes (depending on what happened), my datawindow that I want to use is null and sometimes isn't. When it is null, I'm crashing. So, I want to check for null, but when I tried IsNull(dw_name_of_datawindow), I get the same crash: 

Error : [2]-Null object reference at line...

It appears as though the IsNull() isn't doing what I expected it would. 

Is there a preferred way to check to see if a datawindow is null?

 

Roland Smith Accepted Answer Pending Moderation
  1. Wednesday, 25 May 2022 14:17 PM UTC
  2. PowerBuilder
  3. # 1

Usually when you have a control is null error, the user has closed the window while an event is still running that references that control.

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 25 May 2022 14:23 PM UTC
  2. PowerBuilder
  3. # 2

Hi Troy;

   The DWO is run at "arms length" from either its DW or DataStore Control container. So it's not feasible to use an IsValid() or IsNull() command on the DWO directly in many cases. In my framework though, I use a simple Describe() command that - if it fails - indicates that the DWO within those controls is not present.  HTH

Regards ... Chris

Comment
  1. Chris Pollach @Appeon
  2. Wednesday, 25 May 2022 15:18 PM UTC
DC = DW Control

DS = DataStore

Your App is crashing because you probably need an IsValid() = TRUE *first* on the DC/DS *before* any other PowerScript operations are done.

FWIW: Do NOT use an IsNull() command on either the DS/DC. Only IsValid(). IsNull() is for checking primary data types for nulls - for example: String, Boolean, Integer, etc.

HTH
  1. Helpful
  1. Roland Smith
  2. Wednesday, 25 May 2022 18:09 PM UTC
The real question should be, why is the DW control invalid? One way would be a script closes the window and has lines of code after that. That is poor programming. The other is that the user clicked the X button while the script was running.
  1. Helpful
  1. Roland Smith
  2. Wednesday, 25 May 2022 18:10 PM UTC
If a Close of the window is performed in the middle of a script, there should be a Return immediately after.
  1. Helpful 1
There are no comments made yet.
Brad Mettee Accepted Answer Pending Moderation
  1. Wednesday, 25 May 2022 15:07 PM UTC
  2. PowerBuilder
  3. # 3

Have you tried IsValid instead of IsNull ?

Comment
  1. Troy Cowan
  2. Thursday, 26 May 2022 11:23 AM UTC
Yes, I did try IsValid(dw_mydw) - it behaves the same as IsNull(dw_mydw), which is that the app crashes when dw_mydw is null.

However, we found that IsValid(this) does exactly what I would have expected IsNull(dw_mydw) - or IsValid(dw_mydw) to do - the IsValid(this) returns false when dw_mydw is null and true when it is not. Not intuitive - to me anyways - but does the trick.
  1. Helpful 1
  1. Olan Knight
  2. Sunday, 29 May 2022 22:36 PM UTC
One thing to avoid is the use of AND, use the OR condition instead and use IsValid first:



BAD example: IF ( IsNull (dw_1) AND NOT ( IsValid ( dw_1 )) ) THEN



GOOD example: IF ( NOT ( IsValid ( dw_1 )) OR IsNull (dw_1) ) THEN
  1. Helpful
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Friday, 27 May 2022 05:17 AM UTC
  2. PowerBuilder
  3. # 4

Hi Troy,

You've already got a lot of information about your problem.

Using the Yield() function is always dangerous because it changes the order how code usually runs.

For example: It may be that the user clicks a button or the window close "X". With Yield() Powerbuilder runs the code to close the window with all controls. After that the code after Yield() runs but it looses its context.

So if you use Yield() it is up to you to prevent the user from doing dangerous things.

 

What I usually do:

// instance variable
boolean ib_running = FALSE

-------------------------------------------------------

// the loop
ib_running = TRUE
DO WHILE ...
   Yield()

   // if you want a way to stop the loop
   IF NOT ib_running THEN
      // user stopped the loop
      EXIT
   END IF

   // here your code for the loop

LOOP
ib_running = FALSE

--------------------------------------------------------

// clicked event in a button to stop the loop (if you want it)
ib_running = FALSE

--------------------------------------------------------

// closequery event of the window
// do not allow to close the window if you are in a running loop
IF ib_running THEN return 1

  

HTH,

René

 

 

Comment
  1. Sivaprakash BKR
  2. Friday, 27 May 2022 07:33 AM UTC
As suggested, why not try removing Yield() command and check out?
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Thursday, 26 May 2022 04:46 AM UTC
  2. PowerBuilder
  3. # 5

Can you show us the full error message?

Maybe the problem is not that your datawindow 'is null', but you're trying to access a non existing column (misspelled?) or a non existing row number.

Also can you show us some code?

regards

Comment
  1. Troy Cowan
  2. Thursday, 26 May 2022 11:33 AM UTC
Here is the error message:



Problem#: 3

Date : 05/25/2022 08:50:05

Error : [2]-Null object reference at line 13 in function canleavetab of object uo_ccdf_disasters.

Screen : uo_ccdf_disasters

Object : uo_ccdf_disasters

Event : canleavetab

Line # : 13



Here is the relevant code:



Line 11: dw_grid.ib_nounsavedrfc = false

Line 12: Yield()

Line 13: dw_grid.ib_nounsavedrfc = true



ib_nounsavedrfc is just a boolean that we added to the DW.

Based on what we are doing to reproduce the problem and what I am seeing when it happens, I am pretty sure that dw_grid is null. As mentioned elsewhere in this thread it may be that we've made some mistakes to get into this situation. (Well, our predecessors have anyways - legacy code. :) ). We're going to use IsValid(this) as a band-aid, and work on a bigger fix as we can.



  1. Helpful
  1. Roland Smith
  2. Thursday, 26 May 2022 12:36 PM UTC
If the tab is being closed, that would destroy any controls on it such as dw_grid.
  1. Helpful
  1. Miguel Leeuwe
  2. Thursday, 26 May 2022 14:12 PM UTC
Check if the "CreateOnDemand is checked on the tab. Maybe the tabpage hasn't been created yet, until you activate it for the first time?
  1. Helpful
There are no comments made yet.
Sivaprakash BKR Accepted Answer Pending Moderation
  1. Thursday, 26 May 2022 13:45 PM UTC
  2. PowerBuilder
  3. # 6

Will dw_grid.dataobject come to any use here?
Will checking the result for empty or null solves the issue?

Happiness Always
BKR Sivaprakash

Comment
  1. Troy Cowan
  2. Thursday, 26 May 2022 13:50 PM UTC
If the dw_grid object is still valid, I need to set the boolean value. If it is NOT valid, I need to avoid trying to set the boolean since that would cause the crash.
  1. Helpful
  1. Roland Smith
  2. Thursday, 26 May 2022 15:26 PM UTC
A DataWindow control isn't just going to become invalid for no reason. If the control is on a tab, was a CloseTab method called?

The only time I have run into this issue was when a response window is busy doing processing and I clicked the X button at the top right to close the window.
  1. Helpful 1
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.