Reassigning series valuesources

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
bcmiller
Newbie
Newbie
Posts: 30
Joined: Mon Jan 24, 2005 5:00 am

Reassigning series valuesources

Post by bcmiller » Thu Mar 24, 2005 9:27 pm

My Delphi 2005 application (using TeeChart v7.04 reg) allows users to populate a clientdataset with either of two different sets of fields then displayed in a DBChart. After having specified the new dataset, when I reopen the clientdataset there will be an EDatabase Error:

'clientdataset1: Field 'Brix' not found'.
(Brix is the YValue.ValueSource for Series1 set at design-time)

unless I do the following beforehand:

with DBChart1 do begin
for i := 0 to 5 do Series[ i ].DataSource := nil;
for i := 0 to 5 do Series[ i ].YValues.ValueSource := '';
end;

After reopening the clientdataset I try to reassign the YValues.ValueSources with this code:

for i := 0 to 5 do
with DBChart1.Series[ i ] do begin
Datasource := DM1.cdsRPT0;
YValues.ValueSource := lfFieldList[ i+3 ]; // from a string array
Title := lfCaptionList[ i+3 ];
CheckDatasource;
end;

However the same error message occurs upon executing:

YValues.ValueSource := lfFieldList[ i+3 ];

It still seems to be looking for a previous field that no longer exists in the clientdataset based on the YValueSource design-time setting.

Can it be done this way or do I have to FreeAllSeries and rebuild from scratch?

Thanks in advance,
Barry
Last edited by bcmiller on Sun Apr 10, 2005 8:15 pm, edited 1 time in total.

bcmiller
Newbie
Newbie
Posts: 30
Joined: Mon Jan 24, 2005 5:00 am

Reassigning series valuesources

Post by bcmiller » Mon Mar 28, 2005 4:28 pm

Here's at least some of the causes . . .

1) Things that refers to a field from the previously defined dataset have to be reset based on the new set of fields -or emptied. In this case I was filtering the clientdataset with this:

IndexFieldNames := 'Year;Month;Brix';
SetRange([yr,mo],[yr,mo]);

Year, Month, and Brix are names of fields from the previous dataset and hadn't been reset when the ClientDataSet was reopened.

2) The X and YValue.Valuesources and XLabelsSource need to be set at run-time only.
3) Only create the forms at runtime.

There's probably more... I'll bet there's a simple way of dealing with this, maybe someone will explain.

Post Reply