1. Tom Pod
  2. PowerBuilder
  3. Thursday, 23 January 2020 08:29 AM UTC

Hi,

 

 

I have window called w_window1 with datawindow dw_1.

I would like to call retrieve event on that dw_1 from function test1, but after w_window1.dw_1.retrieve() i got error.

 

Error Number 2.

Error text = Null object reference at line ... in function test1 of object test1.

What am I doing wrong?

 

 

 

Michael Kramer Accepted Answer Pending Moderation
  1. Thursday, 23 January 2020 10:22 AM UTC
  2. PowerBuilder
  3. # 1

Hi Tom,

I presume you mean the Retrieve function.
Retrieve function as part of its work triggers a lot of fevents as the retrieve + display process progresses: RetrieveStart, SQLPreview, DBError, RetrieveRow, RetrieveEnd, RowFocusChanged, ItemFocusChanged

Every "window" consists of two components:

  1. The class = the code incl. properties, functions, and event scripts
  2. A global variable named IDENTICAL to the class

Depending on how you open your window you will see behavior you describe. Code samples:

// ---- ---- ---- ---- ---- EXAMPLE 1 ---- ---- ---- ---- ----
// Use global "class" variable
Open(w_window1)
// NOW: w_window1 references new window of class w_window1 

// NEXT: VALID
w_window1.dw_1.Retrieve( )

// ---- ---- ---- ---- ---- EXAMPLE 2 ---- ---- ---- ---- ----
// Use other variable
w_window1 lw_myWindow
Open(lw_myWindow)
// NOW: lw_myWindow references new window of class w_window1 

// NEXT: VALID
lw_myWindow.dw_1.Retrieve( )

// NEXT: FAILS (global variable unassigned)
w_window1.dw_1.Retrieve( )

In any case you will have to open the window to ensure your code references an valid window reference. You can use IsValid(...) and IsNull(...) to check for valid reference.

// Safest way to check valid reference
if IsValid(w_window1) and not IsNull(w_window1) then
   w_window1.dw_1.Retrieve( )
end if

// Alternative: Assert open window prior to retrieve
if IsNull(w_window1) or not IsValid(w_window1) then
   Open(w_window1)
end if
w_window1.dw_1.Retrieve( )

HTH /Michael

Comment
There are no comments made yet.
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Thursday, 23 January 2020 21:27 PM UTC
  2. PowerBuilder
  3. # 2

Hi Tom;

  If you open "w_window1" from a variable, then it will never exist (aka NULL Object found) as "w_window1". It would exist as "lo_win", in m y example below ...

w_window1  lo_win

String   ls_win = "w_window1"

Open ( lo_win, ls_win)

HTH

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.