INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Passing a structure array

Passing a structure array

(OP)
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 --> Powerbuilder

// 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 --> Powerbuilder

str_Log  lstr_Log[]

lstr_Log = in_NVO.uf_Function() 
So, in this window the lstr_Log is empty ("Children could not be evaluated").

RE: Passing a structure array

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"
www.anvil-of-time.com

RE: Passing a structure array

(OP)
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 --> Powerbuilder

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.

RE: Passing a structure array

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"
www.anvil-of-time.com

RE: Passing a structure array

(OP)
Maybe it works different in the Powerbuilder.Net version? It might be a bug in the .Net version.

RE: Passing a structure array

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.

RE: Passing a structure array

The function should return "ANY" if you want it to return an array:

public function any uf_Function

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close