TAChart: fix for incompatibility, introduced in TListChartSource
Original Reporter info from Mantis: Marcin Wiazowski
-
Reporter name:
Original Reporter info from Mantis: Marcin Wiazowski
- Reporter name:
Description:
It seems that I introduced some incompatibility, when enhancing sorting functionality in TListChartSource, in #35356 (closed) - so I'm attaching a Reproduce demo application, and a patch to fix the problem.
The problem is in TListChartSource.DataPoints property - although this property is not recommended for dealing with TListChartSource, incompatibility should be fixed - at least for such trivial cases, like just assigning a set of completely new contents to the source.
Currently, there is:
procedure TListChartSource.SetDataPoints(const AValue: TStrings);
begin
if FDataPoints = AValue then exit;
BeginUpdate;
try
FDataPoints.Assign(AValue);
if IsSorted then Sort;
finally
EndUpdate;
end;
end;
The problem is inside of the Assign() call - if trying to assign unsorted data to the sorted source, an exception will be raised internally, in TCustomSortedChartSource.ItemInsert(). As a consequence, the Sort() call - that is below the Assign() call - will not have a chance of doing its work.
The solution is simple - FSorted should be temporarily set to False, so Assign() call will succeed - then FSorted should be restored, before the "if IsSorted then Sort" statement.
This could be done directly in TListChartSource.SetDataPoints() - but FDataPoints represents TListChartSourceStrings here (so we have TListChartSourceStrings.Assign() call here) - another one TListChartSourceStrings.Assign() call is also in TListChartSourceStrings.LoadingFinished(), so it's better to fix the problem at the lowest level, i.e. in TListChartSourceStrings.Assign() (in this case, TListChartSource.SetDataPoints() implementation can be simplified).
Exactly same problem occurs also when assigning to TListChartSource.DataPoints.Text, so the attached patch fixes also this problem - this time fix is in TListChartSourceStrings.SetTextStr().
Mantis conversion info:
- Mantis ID: 35664
- Build: 61310
- Version: 2.1 (SVN)
- Fixed in revision: 61314 (#515b8142)