1. Monica Petersen
  2. PowerBuilder
  3. Friday, 16 October 2020 15:19 PM UTC

I'm upgrading from PB 12.5 to 2019 R2 (build 2353) and have come across a problem.  We have a structure that is a set of arrays of each type of variable, that we use to generalize passing parameters.  One of the variable types is an array of powerobjects (po_parm[]):

global type s_parm from structure
string s_parm[]
integer i_parm[]
long l_parm[]
date d_parm[]
datetime dt_parm[]
boolean b_parm[]
decimal dec_parm[]
n_ds ds_object[]
powerobject po_parm[]
any any_parm[]
end type

What I'm finding is that as variables are assigned to the po_parm array, the new value is overwriting all the earlier values.  So, the first element is correct, but when the second element is assigned, the value in the first element is overwritten with the second element, so there are two identical elements.  When the third element is assigned, it overwrites the first and second element with the same values as the third element.

Here's a code sample, if that helps.

FOR li_keyfield = 1 TO li_keyfieldcount
  IF Len(is_keycolumns[li_keyfield]) > 0 THEN
    //get the value from the list
    lstr_keyfield.s_parm[1] = is_keycolumns[li_keyfield]
    lstr_keyfield.s_parm[2] = String(idw_list.of_getitem(ll_rc, is_keycolumns[li_keyfield]))

    //construct a structure of key fields, with field name and field value
    as_key_parm.po_parm[li_keyfield] = lstr_keyfield
  END IF
NEXT

Is this a known bug?

Thanks,

Monica

Miguel Leeuwe Accepted Answer Pending Moderation
  1. Tuesday, 8 June 2021 12:48 PM UTC
  2. PowerBuilder
  3. # 1
Comment
There are no comments made yet.
Ken Guo @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 20 October 2020 06:48 AM UTC
  2. PowerBuilder
  3. # 2

Hi Monica,

Firstly, I suggest you try the method Miguel provided to check whether it works.
Secondly, it is suggested you modify the name of the structure s_parm to make sure it is not the same as its member s_parm[].
Finally, if the issue still exists, it is recommended you report a bug in our support system (https://www.appeon.com/standardsupport/newbug) along with a reproducible case. Thanks in advance.


Regards,
Ken

Comment
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 19 October 2020 23:19 PM UTC
  2. PowerBuilder
  3. # 3

My thought is that the assignment of lstr_key_field to as_key_parm.po_parm, internally is by reference. Every time you do a change to the lstr_key, it will affect all elements which already have been assigned

Try using an array for "lstr_keyfield" instead, by doing something like this:

integer li_count
s_parm lstr_keyfield[]

FOR li_keyfield = 1 TO li_keyfieldcount
  IF Len(is_keycolumns[li_keyfield]) > 0 THEN
	
    li_count ++
        
    //get the value from the list
    lstr_keyfield[li_count].s_parm[1] = is_keycolumns[li_keyfield]
    lstr_keyfield[li_count].s_parm[2] = String(idw_list.of_getitem(ll_rc, is_keycolumns[li_keyfield]))

    //construct a structure of key fields, with field name and field value
    
    as_key_parm.po_parm[li_keyfield] = lstr_keyfield[li_count]
    
  END IF
NEXT

 

Let's see if that fixes the problem.

Regards

Comment
  1. Miguel Leeuwe
  2. Tuesday, 20 October 2020 07:14 AM UTC
BTW: "as_key_parm", is that an argument passed in by reference?

  1. Helpful
  1. Monica Petersen
  2. Tuesday, 20 October 2020 16:13 PM UTC
Hi Miguel, that's a nice solution and it works. I had put a kluge in to save the overwritten variable in a string and then recopy it in, but yours is less awkward.



In the example I sent, the argument was passed in by reference, but this is happening in half a dozen places and in those places the variables are all local. The code's been in place for twelve years and was fine up until PB 12.5, so it definitely seems like a bug.



I'm also going to take Ken's advice and change the name of the structure from s_parm to str_parm, so it doesn't conflict with the string array.



Thanks for your help, I'm excited to try out some of the new 2019 R2 features now that I have things working!



Monica.
  1. Helpful
  1. Miguel Leeuwe
  2. Tuesday, 20 October 2020 16:18 PM UTC
Yw great!
  1. Helpful
There are no comments made yet.
Monica Petersen Accepted Answer Pending Moderation
  1. Monday, 19 October 2020 17:09 PM UTC
  2. PowerBuilder
  3. # 4

But now I'm seeing a similar error in 2019 (build 2170).

 

It seems like the arrays are overwriting each other's memory space.  I have two separate structures.

 

s_parm    lstr_keyparm
s_parm    lstr_keyfield

 

I examine the first array value in lstr_keyparm and it's one thing.  Then I assign a value to lstr_keyfield.  Then I look again at the first array value in lstr_keyparm, and it's overwritten by the value I assigned to lstr_keyfield.  This shows up in the debugger, but I didn't 100% trust it, because it's a little hinky (I can get it to show me two different values for the same variable at the same time).  So I ran it using messageboxes instead of the debugger to say what the values in the arrays are, and see the same behaviour.

 

I tried to reproduce this as a separate stand-alone app, but it works fine there.  It seems to only be a problem on a bigger stage.

 

 

Comment
There are no comments made yet.
Monica Petersen Accepted Answer Pending Moderation
  1. Friday, 16 October 2020 17:13 PM UTC
  2. PowerBuilder
  3. # 5

By the way, I uninstalled 2019R2 and installed 2019, and I'm not seeing this bug anymore.

Comment
  1. Shilpa Rani Bansal
  2. Tuesday, 18 May 2021 19:01 PM UTC
What was the resolution provided by Appeon for this issue. We are facng same issue with PB 2019 R3 latest MR.
  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.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.