Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a structure array

Status
Not open for further replies.

SvenODB

Programmer
Jul 1, 2009
4
0
0
US
I have a window that calls a function of a NonVisualObject. I want the function to return an array of a structure. The array of structure is empty when it returns to the window, alltough I'm sure it's not empty in the function. When I debug the program, and watch to the strucuture array in the Window, I get the message "Children could not be evaluated".
Is it not possible to return a structure array? Or am I doing something wrong?

Example:
I created a structure with 3 elements. F.e. str_Log with elements:
- string s_Function
- long l_Code
- string s_Message

NonVisualObject (n_NVO):
Code:
// Instance variable:
str_Log   istr_Log[]

public function str_Log[]  uf_Function
  ...
  istr_Log[1].s_Function = "uf_Function"
  istr_Log[1].l_Code = 2051
  istr_Log[1].s_Message = "Some text..."

  // some more records could be added here ...
  ...

  return istr_Log

Window (w_Window):
Code:
str_Log  lstr_Log[]

lstr_Log = in_NVO.uf_Function()
So, in this window the lstr_Log is empty ("Children could not be evaluated").
 
Change the method on your NVO and pass the structure by reference.

So your code would become:
Code:
str_Log  lstr_Log[]

in_NVO.uf_Function(lstr_Log)

You might want to return an integer to indicate success/failure.

Matt

"Nature forges everything on the anvil of time"
 
OK, passing as reference parameter works. I will do it that way.

FYI:
* while I was trying some things I found out that this doesn't work either:
Code:
str_Log   lstr_Log1[]
str_Log   lstr_Log2[]

// some code to file lstr_Log1

lstr_Log2 = lstr_Log1
lstr_Log2 is empty here.

* Passing a filled structure array as parameter by value to another method also does not work. The array is empty in the receiving method.
in_NVO.uf_Function2(lstr_Log) ==> lstr_Log is empty in method uf_Function2.
 
There must be something else going on. I use code similar to your second example (lstr_Log2 = lstr_Log1) quite often without issue.

Matt

"Nature forges everything on the anvil of time"
 
Maybe it works different in the Powerbuilder.Net version? It might be a bug in the .Net version.
 
Have you tried wrapping your structure array inside another structure? You could include a success variable at that level, along with your structure array. Sadly, I've not tried passing arrays in more modern versions of PB, but in earlier versions they did not work... So that's when we started using a "header structure" to house the "detail structure array".

e.g. str_Hdr would have two variables: 1.) l_result (long) and 2.) s_log[ ] (str_Log)

It would add another level to the dot-notation, but would be worth a shot to see if this cures the issue.
 
The function should return "ANY" if you want it to return an array:

public function any uf_Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top