TAChart: Prevent out-of-range access with AccumulationRange=0 and AccumulationMethod=camDerivative

git-svn-id: trunk@32205 -
This commit is contained in:
ask 2011-09-07 10:08:08 +00:00
parent 643751d975
commit 50521088ff

View File

@ -164,7 +164,7 @@ type
TCalculatedChartSource = class(TCustomChartSource)
private
FAccumulationMethod: TChartAccumulationMethod;
FAccumulationRange: Integer;
FAccumulationRange: Cardinal;
FHistory: TChartSourceBuffer;
FIndex: Integer;
FItem: TChartDataItem;
@ -181,7 +181,7 @@ type
procedure Changed(ASender: TObject);
procedure ExtractItem(out AItem: TChartDataItem; AIndex: Integer);
procedure SetAccumulationMethod(AValue: TChartAccumulationMethod);
procedure SetAccumulationRange(AValue: Integer);
procedure SetAccumulationRange(AValue: Cardinal);
procedure SetOrigin(AValue: TCustomChartSource);
procedure SetPercentage(AValue: Boolean);
procedure SetReorderYList(const AValue: String);
@ -198,7 +198,7 @@ type
published
property AccumulationMethod: TChartAccumulationMethod
read FAccumulationMethod write SetAccumulationMethod default camNone;
property AccumulationRange: Integer
property AccumulationRange: Cardinal
read FAccumulationRange write SetAccumulationRange default 2;
property Origin: TCustomChartSource read FOrigin write SetOrigin;
@ -817,7 +817,10 @@ procedure TCalculatedChartSource.CalcAccumulation(AIndex: Integer);
var
i, ar: Integer;
begin
FHistory.Capacity := AccumulationRange;
if (AccumulationMethod = camDerivative) and (AccumulationRange = 0) then
FHistory.Capacity := 10
else
FHistory.Capacity := AccumulationRange;
ar := IfThen(AccumulationRange = 0, MaxInt, AccumulationRange);
if FIndex = AIndex - 1 then begin
ExtractItem(FItem, AIndex);
@ -993,7 +996,7 @@ begin
Changed(nil);
end;
procedure TCalculatedChartSource.SetAccumulationRange(AValue: Integer);
procedure TCalculatedChartSource.SetAccumulationRange(AValue: Cardinal);
begin
if FAccumulationRange = AValue then exit;
FAccumulationRange := AValue;