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 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 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 messagebox('Output Tester 2 Name', lstr_output.as_name)//Here it’s supposed to output “Tester 2”, however, it outputs “Tester 3” instead.
PowerBuilder 2021 GA Build 1288
This is a known bug in PowerBuilder and will be fixed in the next MR version.
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 attached hotfix DLL to solve this issue following the steps below:
1) Download the attachment.
2) Decompress the attachment and you’ll find the Runtime 18.104.22.1688 folder inside. Replace the files of the same name in the directory of C:\Program Files (x86)\Appeon\Common\PowerBuilder\Runtime 22.214.171.1248 on the development machine with the DLLs in this Runtime 126.96.36.1998 folder. (Note: Please back up your original files before replacement.)
3) Check and make sure the Runtime version used in PowerBuilder IDE is 188.8.131.528.
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 184.108.40.2068 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.