Symptom
You can get corrupted data if you directly assign the DataWindow values that were initially retrieved from the database (e.g. dwcontrol.Object.Data.Primary.Original) to the current values in the DataWindow control (e.g. dwcontrol.Object.Data.Primary.Current)
Environment
PowerBuilder
Reproducing the Issue
-
Unzip the repro.zip file
-
Run the application
-
Select menu File > New > Untitled for Sheet1
-
Scroll to the end of the result set of the the DataWindow control belonging to first tabpage
-
Switch back and forth several times between second tabpage and first tabpage to display corrupted data
Cause
-
Expressions like dwcontrol.Object.Data.Primary.Original on the right hand side create an array with content pointing to data in the DataWindow itself. This means that the data in the array is not owned by the array itself but by the DataWindow. This was implemented as is since very old versions of PowerBuilder (e.g PB 6.x). It works with no problem when the DataWindow data are numeric but may fail for allocated data like strings. Strings are shared and not copied. When you assign values to same DataWindow primary buffer, data overlap. Assignment causes de-allocation of old data. So the right hand side array may contain de-allocated string memory causing the funny characters.
-
This is not a problem when the right hand side and left hand side are not the same buffer or even the same DataWindow.
Solution
Use an intermediate temporary variable of type any to pass the data from one source to another. For example:
any lany lany = dwcontrol.object.data.primary.original dwcontrol.object.data.primary.current = lany
Attachment: repro.zip, dw_main.srd, dw_nested.srd