Page 1 of 1

Exception in TChartseries.GetValueColor

Posted: Wed Nov 19, 2008 10:39 am
by 10548594
When I add several points to a TLineseries and afterwards call Chart1.Refresh, it runs into an endless loop of exceptions:
EListError: List index out of bounds (-1). The exception occurs in TeEngine.pas in "TChartSeries.GetValueColor", where Internalcolor(ValueIndex) is called.

I use several TLineseries in this chart, and I set "Coloreach" to true and added points using AddXY with different colors. As this old project is kind of really big, it's difficult to provide an example project ... And I was not able to reproduce the error in a new project.

However, it does not occur if AddXY is only used without a parameter for "aColor".

Further investigation showed that the Problem is in Line 2172 of Series.pas:

if IsNull(ValueIndex-1) then { if null }

When FColor is assigned (which is only when a Series has colors different from clTeeColor) and ValueIndex=0, this function tries to get an item with index -1 in the list which is not accessible.

Edit:
As a bugfix, I changed the above line to

if IsNull(ValueIndex) then { if null }

is this the right solution?

Posted: Wed Nov 19, 2008 3:40 pm
by narcis
Hi MarkusM,

It's difficult for us to say without being able to reproduce the issue here. Most likely there's a reason for that "-1" but I can tell this for sure on those conditions. Can you reproduce this with v8.04, which is the latest version available at the client area?

Thanks in advance.

Posted: Wed Nov 19, 2008 4:37 pm
by 10548594
I'm sorry, but I was not able to reproduce this error in a single application. As it works now for me, I have no problem any more ... Sorry.

To avoid errors like this in the future, you could change

Function TChartSeries.InternalColor(ValueIndex:Integer):TColor;
Begin
if Assigned(FColors) and (FColors.Count>ValueIndex) then
result:=TColor(FColors{$IFOPT R-}.List{$ENDIF}[ValueIndex])
else
result:=clTeeColor;
end;

to

Function TChartSeries.InternalColor(ValueIndex:Integer):TColor;
Begin
if Assigned(FColors) and (FColors.Count>ValueIndex) and (ValueIndex >= 0) then
result:=TColor(FColors{$IFOPT R-}.List{$ENDIF}[ValueIndex])
else
result:=clTeeColor;
end;

... because the color of a point in my opinion is not important enough to throw an exception if it is called with "-1".

OR

you try to find the reason for the "-1" ;-)

Would be better than waiting till another customer complains about it, wouldn't it?

Posted: Wed Nov 19, 2008 4:46 pm
by narcis
Hi MarkusM,

Thanks for the information.

The best way for addressing this issue would be finding how to reproduce it consistenly so we can be sure of what is causing it and can go to the root of the problem.