Page 1 of 1
Problems using a function at runtime
Posted: Tue Jan 17, 2006 1:18 pm
by 9231248
Hello
I am trying to add a RMS function series to my chart.
When I try to view my chart the new series that should have been added is not displayed, and I get an access violation
I am trying to do this at runtime, but I cant see that this should cause a problem?
Is it important what I use as the owner?
I have used the line below
objChart.Chart.Series[0].SetFunction(TRMSFunction.Create(objChart.Chart.Series[0]));
where objChart is my chart
Cheers
Paul
Posted: Tue Jan 17, 2006 1:50 pm
by narcis
Hi Paul,
Have you read "Tutorial 7 - Working with Functions"? You'll find the tutorials at the "Docs" folder in the TeeChart program group.
BTW: It works fine here, you should do something like:
Code: Select all
procedure TForm1.FormCreate(Sender: TObject);
var
tmpBarSeries1,tmpBarSeries2:TBarSeries;
tmpLineSeries:TLineSeries;
begin
With Chart1 do
begin
//Add 2 data Series
tmpBarSeries1:=TBarSeries.Create(self);
tmpBarSeries2:=TBarSeries.Create(self);
AddSeries(tmpBarSeries1);
AddSeries(tmpBarSeries2);
//Populate them with data (here random)
tmpBarSeries1.FillSampleValues(10);
tmpBarSeries2.FillSampleValues(10);
//Add a series to be used for an Average Function
tmpLineSeries:=TLineSeries.Create(self);
AddSeries(tmpLineSeries);
//Define the Function Type for the new Series
tmpLineSeries.SetFunction(TRMSFunction.Create(self));
//Define the Datasource for the new Function Series
//Datasource accepts the Series titles of the other 2 Series
tmpLineSeries.DataSources.Clear;
tmpLineSeries.DataSources.Add( tmpBarSeries1 );
tmpLineSeries.DataSources.Add( tmpBarSeries2 );
// *Note - When populating your input Series manually you will need to
// use the Checkdatasource method
// - See the section entitled 'Defining a Datasource'
//Change the Period of the Function so that it groups averages
//every 2 Points
tmpLineSeries.FunctionType.Period := 2;
end;
end;
Posted: Tue Jan 17, 2006 2:55 pm
by 9231248
Thanks for this
I will give this a go now
My chart is set up inside a report builder report. I would prefer to have the series added and set up ready to go at design time so that when the report template is loaded my chart is just ready for the data
However, as soon as I put a series with a function onto my chart, my application goes mental when I close, do you know of any issues with objects being freed twice? When using FastMem it shows that an attempt is being made to free a function object twice
I get access violations, invalid pointer operations, etc
Posted: Fri Jan 20, 2006 12:30 pm
by Pep
Hi Paul,
I think the problem is a bug in TeeChart code. In short, in combination with Report Builder and if chart series datasource is another series or function, then the destroying mechanism tries to free/destroy series (and functions) which were already freed.
We've fixed the problem for series in TeeChart v7.0 and right now we're tackling the function problem.
A temporary solution/workaround is to disconnect and free functions/series in code at runtime before report (form) is destroyed.