Page 1 of 1
SaveChartToXMLStream and LoadChartFromStream problem
Posted: Wed Jul 05, 2023 8:53 am
by 16565015
Hello,
I need to save and load Chart, customized by a end-user, to a Memo field dataset. So I need save a text the best way for maintenance/update/fix. I need XMl or INI or a plain text format.
I have tried to use these methods :
SaveChartToXMLStream
Code: Select all
procedure TForm1.BSaveClick(Sender: TObject);
var
lStringStream:TStringStream;
begin
lStringStream:= TStringStream.Create;
try
SaveChartToXMLStream(chart1, lStringStream);
lStringStream.Position:=0;
MemoXML.Lines.LoadFromStream(lStringStream );
finally
lStringStream.Free;
end;
end;
LoadChartFromStream
Code: Select all
procedure TForm1.BLoadClick(Sender: TObject);
var
lStringStream:TStringStream;
begin
lStringStream:= TStringStream.Create;
try
MemoXML.Lines.savetoStream(lStringStream);
lStringStream.Position:=0;
LoadChartFromStream(chart1, ConvertXMLToText(lStringStream) );
finally
lStringStream.Free;
end;
end;
SaveChartToXMLStream seems to work.
But after I can't load it with LoadChartFromStream ?
Full sample in attachment :
1) Double click on Chart -> Modify it foir example add a seire with random values
2) Try save -> seems to be Ok
3) Try load -> Chart became empty, try a second time Chat become invisible etc...
Using TTeeXMLSource doesn't help because I don't understand how to use it without a file :
https://www.steema.com/docs/teechart/vc ... rial15.htm
I need a LoadChartFromXMLStream or LoadChartFromXMLTSTringsStream/SaveChartToXMLTStrings ?
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Wed Jul 05, 2023 2:36 pm
by yeray
Hello,
There was a
TSplitter
inside the TChart object that was giving problems. Without it, I get a "Property Marks.OnTop does not exist" error.
Using
SaveChartToStream
works fine for me here:
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Thu Jul 06, 2023 9:16 am
by 16565015
Hello,
Thank you for answer.
So it's a "visual" (all component state and all that it's content) saving with the events (OnDblClick etc.) saving.
It's a problem to maintain and version changing or if you add event or change event name or modify a simple Tchart.align etc.
Does it exists a way to save to XML (or ini or text) only serie content = Only that the end-user or a designer at runtime can change in TChartEditor (.execute) dialog ?
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Thu Jul 06, 2023 2:50 pm
by yeray
Hello,
Yes, the "SaveChart" methods use a TWriter
to save the full component state.
If you don't want anything present in the Chart to be exported, you can temporally remove it before exporting, and restore it afterwards.
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Thu Jul 06, 2023 4:17 pm
by 16565015
Hello,
Thank you for answer.
No it's not useable in my case because I don't see how to remove some properties and Events saved. Like in my sample, I don't want to save/restore :
Code: Select all
Align = alClient
TabOrder = 0
OnDblClick = Chart1DblClick
ExplicitWidth = 685
DefaultCanvas = 'TGDIPlusCanvas'
ColorPaletteIndex = 0
I only want to save and restore Series properties value. All that a End-user can change in a TChartEditor (.execute) dialog. This dialog is nice because we can choose that Options (ceAdd, ceDelete etc.) the user can change. But we can't easily save/load it (in XML) !!!!
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Fri Jul 07, 2023 7:58 am
by yeray
Hello,
The editor only modifies chart properties as you would do by code. Then, I'm afraid we can't identify what properties have been modified through the editor when exporting a chart.
You could use a temporal chart, created at runtime, where you can control what properties you copy to it from your main chart. Then you can export that temporal chart.
You can also apply the same concept at the loading stage. You can load the stream to a temporal chart and only copy those properties you want to the destination chart.
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Fri Jul 07, 2023 8:50 am
by 16565015
Hello,
Thank you for answer.
LoadChartFromStream / SaveChartToStream are not far from what I want.
I only need an event :
OnSaveChartToSteam(APropertyName:String;ASaved:Boolean) to allow which property to save.
Or better if you know Devexpress something like OnSetStoredPropertyValue/OnSetStoredPropertyValue :
https://docs.devexpress.com/VCL/cxGridB ... pertyValue
https://docs.devexpress.com/VCL/cxGridB ... Properties
Do you think that it can be possible in a future version ? Because I haven't time to code it for the moment.
With this you can allow your end-user or designer (not developer) to easily make dash-board. I need it in my CRM software where a dash-Board exists but without your Teechart for the moment...
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Thu Jul 13, 2023 4:21 pm
by yeray
Hello,
I've added it to the public tracker (
#2621).
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Thu Jul 13, 2023 5:14 pm
by 16565015
Hello Yeray,
I've added it to the public tracker (#2621).
Thank you !
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Fri Jul 14, 2023 6:43 am
by yeray
Hello,
The latest version (v2023.38) adds
SaveChartToString
/
LoadChartFromString
which could do the job without having to add a new event into the Chart. Here the example:
Code: Select all
procedure TForm1.BSaveClick(Sender: TObject);
var lStringList:TStringList;
procedure DeleteIfExists(prop: string);
var idx: Integer;
begin
idx:=lStringList.IndexOf(prop);
if idx>=0 then
lStringList.Delete(idx);
end;
begin
lStringList:=TStringList.Create;
lStringList.Text:=SaveChartToString(Chart1);
DeleteIfExists('Marks.OnTop');
MemoXML.Lines:=lStringList;
end;
procedure TForm1.BLoadClick(Sender: TObject);
begin
LoadChartFromString(Chart1, MemoXML.Lines.Text);
end;
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Tue Jul 18, 2023 4:04 pm
by 16565015
Hello Yeray,
The latest version (v2023.38) adds SaveChartToString/LoadChartFromString
Yes SaveChartToString and LoadChartFromString can do the trick. But these two methods seems to call SaveChartToStream/LoadChartFromStream, right ?
I think that it's a bit more complicated for multiline properties like
etc..
So handling of '(' + ')' and '{' + '}' is needed !
What is more because of spaces "IndexOf" and "IndexOfName" doesn't work.
That's why an event which contains each parsed property value could be really more easy to handle.
But I have done my own function to handle that...
The editor only modifies chart properties as you would do by code.
My software contains a powerful dashboard editor where we can display a mix of views (from customisable queries) of :
- Grids (Classic, vertical, tree etc...)
- Pivots (cross table)
- Scheduler
- Charts (Your teechart in the next version)
- etc...
In most of cases this dash board is made by integrator (Computer scientist with very different levels) but sometime enhanced users. So your Chart editor is very fine for that. And save/load to a dataset which contain each view layout is required. And save it to text because binary is not maintainable.
Re: SaveChartToXMLStream and LoadChartFromStream problem
Posted: Wed Jul 19, 2023 6:51 am
by yeray
Hello,
Fab wrote: ↑Tue Jul 18, 2023 4:04 pm
But I have done my own function to handle that...
It would be interesting to take a look at that code if you want to share it.
Yeray wrote: ↑Fri Jul 07, 2023 7:58 am
You can also apply the same concept at the loading stage. You can load the stream to a temporal chart and only copy those properties you want to the destination chart.
Regarding this idea, you probably don't even need a temporal chart. You can just load the stream - with those properties you don't want - and manually reset them to the values you wish afterwards.
You could have a small function that resets those properties you want to discard.
Finally note we use to discourage giving users access to the Chart Editor. The Chart Editor is made to help developers to design their charts; it's not intended or recommended for the final user because it has so many options it's quite easy to set options with little or no sense.