From 515b81420bea3a11a811b1e7a35cfdce24fbaf88 Mon Sep 17 00:00:00 2001 From: wp Date: Mon, 3 Jun 2019 22:00:04 +0000 Subject: [PATCH] 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 - --- components/tachart/tasources.pas | 56 ++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/components/tachart/tasources.pas b/components/tachart/tasources.pas index 5fb535949f..543d3ff736 100644 --- a/components/tachart/tasources.pas +++ b/components/tachart/tasources.pas @@ -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;