PowerObject array values in a structure being overwritten

Symptom

In the ancestor object, if a structure contains a PowerObject array, when you assign a value to structure.powerobject[n], the same value will also overwrite the values of structure.powerobject[1] to structure.powerobject[n-1], that is, all of their values become the same as the value of structure.powerobject[n].

Here is the example code:

global type str_main from structure
       powerobject   astr_sub[]
end type
global type str_sub from structure
       string       as_name
end type
Long           i, j = 1
String         ls_name
str_sub        lstr_input, lstr_output, lstr_empty
str_main       lstr_storage
FOR i = 1 TO 3
   s_name= "Tester " + String(i)
   str_input.as_name = ls_name
   lstr_storage.astr_sub[j] = lstr_input //The bug happens here.
   j ++
NEXT
lstr_output = lstr_storage.astr_sub[1]
messagebox('Output Tester 1 Name', lstr_output.as_name)//Here it’s supposed to output "Tester 1", however, it outputs "Tester 3" instead.
lstr_output = lstr_storage.astr_sub[2]
messagebox('Output Tester 2 Name', lstr_output.as_name)//Here it’s supposed to output "Tester 2", however, it outputs "Tester 3" instead.

Environment

PowerBuilder 2021 GA Build 1288

Cause

This is a known bug in PowerBuilder and will be fixed in the next MR version.

Solution

You can use one of the following approaches to resolve the issue. 

1. Adopt the following workaround

After you assign a value to the PowerObject in the structure, clear the structure right away. This way, the next time you assign a value to the structure, it will be an empty structure. Below is the example code:

FOR i = 1 TO 3
        ls_name= "Tester " + String(i)
        lstr_input.as_name = ls_name
        lstr_storage.astr_sub[j] = lstr_input
        lstr_input = lstr_empty //Clear the structure to work it around.
        j ++
NEXT

2. Use the hotfix DLL

Appeon has fixed this bug. You can use the following hotfix DLL to solve this issue:

1) Download hotfix_dll_1288_for_structureissue.zip.

2) Decompress the zip file and you’ll find the Runtime 21.0.0.1288 folder inside. Replace the files of the same name in the directory of C:\Program Files (x86)\Appeon\Common\PowerBuilder\Runtime 21.0.0.1288 on the development machine with the DLLs in this Runtime 21.0.0.1288 folder. (Note: Please back up your original files before replacement.)

3) Check and make sure the Runtime version used in PowerBuilder IDE is 21.0.0.1288.

4) Full Build your application in PowerBuilder IDE. Please note that if there are PBD files in your PBT, you need to regenerate these PBD files using the corresponding PBL.

5) Run your application in the development environment and the bug should be solved by now.

6) If you are to deploy the application to the production environment, you need to copy all the DLLs of this hotfix to replace the files of the same name in the directory of C:\Program Files (x86)\Appeon\Common\PowerBuilder\Runtime 21.0.0.1288 on the client machine. If the client machine doesn’t have PB Runtime installed and all the PB Runtime files were deployed to the directory of the EXE, then you need to copy the DLLs in this hotfix to replace the corresponding files in the EXE directory.