Page 1 of 1

Confused by Chart1[i] notation

Posted: Wed Oct 27, 2010 5:30 pm
by 16457492
Hi,

I'm reading through a code example provided by Yeray ยป 03 May 2007 08:44. Here's a piece of that code.

for i := 0 to nSeries-1 do
begin
Chart1.AddSeries(TLineSeries);
Chart1.CustomAxes.Add;
Chart1.CustomVertAxis := Chart1.CustomAxes.Items;
Chart1.CustomAxes.Items.Axis.Color := Chart1.Color;
Chart1.CustomAxes.Items.Grid.Visible := False;
ComboBox2.Items.Add('Series' + inttostr(i + 1));
Chart1.FillSampleValues(20000);
Chart1.CustomAxes.Items.PositionUnits := muPixels;
if ((i+1) mod 2 = 0) then
Chart1.CustomAxes.Items.OtherSide := True;
end;

I'm confused by the array index attached to some of the Chart1 references in that code. I'm clearly missing something because that notation doesn't make any sense to me. The notation Chart1 suggests there is an array of several charts, however, I'm reasonably sure the example was meant to apply to a single instance of a single TChart component. I haven't been able to find anything in the documentation that suggests why this notation is valid. Can you explain what Yeray is up to there?
Thanks!
Brian

Re: Confused by Chart1[i] notation

Posted: Thu Oct 28, 2010 2:13 am
by 9244525
Chart1 refers to the series for Chart1.

Re: Confused by Chart1[i] notation

Posted: Thu Oct 28, 2010 3:05 am
by 16457492
Thank you for the reply. That's very helpful. I accept that answer although the syntax still doesn't make sense to me. I can't quite picture the underlying structure. It's probably obvious if you study the TeeChart source code - which I don't have. It's enough for my purposes right now to understand what the code does even if I don't know why that particular syntax works. Thanks again.

Re: Confused by Chart1[i] notation

Posted: Thu Oct 28, 2010 11:38 am
by narcis
Hi bfalter,

Using Chart1 is the same as using Chart1.Series. I guess it was made for simplicity since most common objects to be in a chart are series but you can freely use the latter if you prefer.

Re: Confused by Chart1[i] notation

Posted: Thu Oct 28, 2010 4:36 pm
by 16457492
Hi Narcis,

Thanks for the explanation. Everything makes sense now.

Best regards,
Brian