Steema Issues Database

Note: This database is for bugs and wishes only. For technical support help, if you are a customer please visit our online forums;
otherwise you can use StackOverflow.
Before using this bug-tracker we recommend a look at this document, Steema Bug Fixing Policy.



Bug 609

Summary: Streaming of classes derived from TChart affected
Product: VCL TeeChart Reporter: trubetskov
Component: ChartAssignee: Steema Issue Manager <issuemanager>
Status: RESOLVED FIXED    
Severity: major CC: david, sandra
Priority: ---    
Version: 140220   
Target Milestone: ---   
Hardware: PC   
OS: Windows   
Chart Series: --- Delphi / C++ Builder RAD IDE Version:
Attachments: Project demonstrating this problem. The chart should NOT change after pressing the button

Description trubetskov 2014-02-27 09:02:38 EST
Created attachment 104 [details]
Project demonstrating this problem. The chart should NOT change after pressing the button

This example demonstrates a new subtle problem with streaming of
classes derived from TChart. Compare how it works with the current release
Feb 2014 and with the previous release Nov 2013.

In the derived class View3D has default setting = False.
Unfortunately LoadChartFromStream recreates a class of TCustomChart type and
uses its default settings, therefore any new defaults in the derived class get lost.

It happens due to the replacement of the following lines in the procedure TeeStore.LoadChartFromStreamCheck:

  { remove all child Series and Tools }
  AChart.FreeAllSeries;
  AChart.Tools.Clear;

with

  AChart.ClearChart;

in the Feb 2014 version.

This problem affects all other attempts to override properties of TChart in the derived classes! In order to fix this issue I reimplemented LoadChartFromStream without calling "ClearChart" inside.
Comment 1 david berneda 2014-02-28 06:09:04 EST
Fixed. ClearChart now uses the current ClassType to call the Create constructor properly.  


Procedure TCustomChart.ClearChart;

  procedure InitChart;
  type
    TCustomChartClass=class of TCustomChart;

  var tmpChart : TCustomChart;
      tmpClass : TCustomChartClass;
  begin
    // Use ClassType to call derived classes Create constructor
    tmpClass:=TCustomChartClass(ClassType);

    tmpChart:=tmpClass.Create(nil);
    try
      tmpChart.Parent:=Parent;
      Assign(tmpChart);
    finally
      tmpChart.Free;
    end;
  end;

var t : Integer;
begin
  for t:=0 to SeriesCount-1 do
    if Assigned(Series[t].Datasource) then
      {$IFDEF TEEOCX}
      {$IFDEF DATABASE}
      if (Series[t].DataSource is TTeeADOQuery) then
         Series[t].Datasource.Free
      else
      {$ENDIF}
      {$ENDIF}
        Series[t].Datasource:=nil;

  FreeAllSeries;
  SeriesList.Clear; //TV52015747
  Tools.Clear;
  Animations.Clear;

  for t:=0 to Axes.Count-1 do
      Axes[t].Items.Clear;

  Axes.Reset;

  InitChart;
end;