Hi,
I find it very useful to stream complex charts into a database blob field for use as templates. But I need to save extra properties for each series such as the gauging location and variate the data represents, the file from which the data comes, and the index of the series in that file. I can subclass the various classes of TChartSeries to add in these properties.
Using TeeChart Pro 2014.12.140923, the SaveChartToStream method recognises some, but not all, of my extra properties, and these appear in the saved BLOB field. But the SaveChartToStream method doesn't recognize my subclass name, so it's difficult to retrieve these extra properties. How can I make this work? How can I store and retrieve extra properties when streaming charts? Is a TagObject included in the stream? That would be very handy.
Thanks for any advice.
Toreba
Saving charts to stream with extra properties
Re: Saving charts to stream with extra properties
Hello,
Have you tried overriding DefineProperties and adding there the properties to serialize?
This works fine for me here:
Have you tried overriding DefineProperties and adding there the properties to serialize?
This works fine for me here:
Code: Select all
uses TeeStore;
type TMyBarSeries = class(TBarSeries)
private
procedure WriteBarName(Writer: TWriter);
procedure ReadBarName(Reader: TReader);
procedure WriteBarID(Writer: TWriter);
procedure ReadBarID(Reader: TReader);
protected
IBarNameStored: boolean;
IBarName: string;
IBarID: Integer;
procedure DefineProperties(Filer:TFiler); override;
public
property BarName: string read IBarName write IBarName stored IBarNameStored;
property BarID: Integer read IBarID write IBarID default -1;
end;
procedure TMyBarSeries.DefineProperties(Filer: TFiler);
begin
inherited;
Filer.DefineProperty('BarName',ReadBarName,WriteBarName,True);
Filer.DefineProperty('BarID',ReadBarID,WriteBarID,True);
end;
procedure TMyBarSeries.WriteBarName(Writer: TWriter);
begin
Writer.WriteIdent(BarName);
end;
procedure TMyBarSeries.ReadBarName(Reader: TReader);
begin
BarName:=Reader.ReadIdent;
end;
procedure TMyBarSeries.WriteBarID(Writer: TWriter);
begin
Writer.WriteInteger(BarID);
end;
procedure TMyBarSeries.ReadBarID(Reader: TReader);
begin
BarID:=Reader.ReadInteger;
end;
procedure TForm1.FormCreate(Sender: TObject);
var memStream1: TStream;
begin
RegisterClass(TMyBarSeries);
Chart1.View3D:=false;
Chart1.Legend.Visible:=false;
with Chart1.AddSeries(TMyBarSeries) as TMyBarSeries do
begin
BarID:=1;
BarName:='MyBar #' + IntToStr(BarID);
FillSampleValues;
ColorEachPoint:=true;
end;
memStream1:=TMemoryStream.Create;
SaveChartToStream(Chart1, memStream1);
memStream1.Position:=0;
LoadChartFromStream(Chart2, memStream1);
Chart2.Top:=Chart1.Top+Chart1.Height+10;
Memo1.Clear;
Memo1.Lines.Add(IntToStr((Chart1[0] as TMyBarSeries).BarID));
Memo1.Lines.Add((Chart1[0] as TMyBarSeries).BarName);
Memo1.Lines.Add(IntToStr((Chart2[0] as TMyBarSeries).BarID));
Memo1.Lines.Add((Chart2[0] as TMyBarSeries).BarName);
end;
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Saving charts to stream with extra properties
Yeray,
Wow, I didn't know I could do any of that, and it works!
Though I notice that if my extra properties are published rather than public, then they appear in the streamed version anyway, it seems, but that default mechanism can't cope with enumerated types. So if I also add them using the method you've shown me they appear twice in the streamed version. I've downgraded from published to public and now have proper control of data type using the methods passed to TFiler.DefineProperty
If I'm using many different series types, then all this coding gets very repetitive. I presume the only way to avoid this is to get the source code for TChartSeries, and add my properties in there.
Thanks very much for your help.
Toreba
Wow, I didn't know I could do any of that, and it works!
Though I notice that if my extra properties are published rather than public, then they appear in the streamed version anyway, it seems, but that default mechanism can't cope with enumerated types. So if I also add them using the method you've shown me they appear twice in the streamed version. I've downgraded from published to public and now have proper control of data type using the methods passed to TFiler.DefineProperty
If I'm using many different series types, then all this coding gets very repetitive. I presume the only way to avoid this is to get the source code for TChartSeries, and add my properties in there.
Thanks very much for your help.
Toreba
Re: Saving charts to stream with extra properties
Hello Toreba,
I'm not sure your only option is to modify the TeeChart sources.
I'd suggest you to read the documentation here.
I'm not sure your only option is to modify the TeeChart sources.
I'd suggest you to read the documentation here.
Since you have the TeeChart sources, you'll see we use published properties to store custom enums, ie the MultiBar property in TCustomBarSeries.Toreba wrote:but that default mechanism can't cope with enumerated types
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |