TAChart: Fix issue with sorted TListChartSource when unsorted data are added via DataPoints property. Issue #35664, patch by Marcin Wiazowski.

git-svn-id: trunk@61314 -
This commit is contained in:
wp 2019-06-03 22:00:04 +00:00
parent 96442a5bea
commit 515b81420b

View File

@ -304,10 +304,12 @@ type
function Get(Index: Integer): String; override;
function GetCount: Integer; override;
procedure Put(Index: Integer; const S: String); override;
procedure SetTextStr(const Value: string); override;
procedure SetUpdateState(AUpdating: Boolean); override;
public
constructor Create(ASource: TListChartSource);
destructor Destroy; override;
procedure Assign(Source: TPersistent); override;
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Insert(Index: Integer; const S: String); override;
@ -324,6 +326,29 @@ end;
{ TListChartSourceStrings }
procedure TListChartSourceStrings.Assign(Source: TPersistent);
var
SaveSorted: Boolean;
begin
BeginUpdate;
try
// new data may come unsorted - to avoid exception in TCustomSortedChartSource.
// ItemInsert() in this case, we disable FSorted temporarily - then we'll sort
// the whole dataset if needed
SaveSorted := FSource.FSorted;
try
FSource.FSorted := false;
inherited Assign(Source);
finally
FSource.FSorted := SaveSorted;
end;
if FSource.IsSorted then FSource.Sort;
finally
EndUpdate;
end;
end;
procedure TListChartSourceStrings.Clear;
begin
if not (csLoading in FSource.ComponentState) then
@ -501,6 +526,29 @@ begin
end;
end;
procedure TListChartSourceStrings.SetTextStr(const Value: string);
var
SaveSorted: Boolean;
begin
BeginUpdate;
try
// new data may come unsorted - to avoid exception in TCustomSortedChartSource.
// ItemInsert() in this case, we disable FSorted temporarily - then we'll sort
// the whole dataset if needed
SaveSorted := FSource.FSorted;
try
FSource.FSorted := false;
inherited SetTextStr(Value);
finally
FSource.FSorted := SaveSorted;
end;
if FSource.IsSorted then FSource.Sort;
finally
EndUpdate;
end;
end;
procedure TListChartSourceStrings.SetUpdateState(AUpdating: Boolean);
begin
if not (csLoading in FSource.ComponentState) then
@ -741,13 +789,7 @@ end;
procedure TListChartSource.SetDataPoints(const AValue: TStrings);
begin
if FDataPoints = AValue then exit;
BeginUpdate;
try
FDataPoints.Assign(AValue);
if IsSorted then Sort;
finally
EndUpdate;
end;
FDataPoints.Assign(AValue);
end;
function TListChartSource.SetText(AIndex: Integer; const AValue: String): Integer;