Page 1 of 1
Is there a "Change" Flag for Teechart?
Posted: Mon Jun 07, 2010 1:00 pm
by 13050364
Hello Support
Id like to be able to prompt the user if he/she would like to save changes before closing the chart.
Is there a flag I can check that will tell me if the user has made any changes using the chart editor?
regards
Re: Is there a "Change" Flag for Teechart?
Posted: Wed Jun 09, 2010 10:54 am
by 13050364
Hi
Maybe Ive not explained this well enough.
Im developing a windows application using C#.NET. The application contains a form that includes a TChart.
I have provided an option that lets the user use the Tchart editor. As most of you will know this allows the user to change things such as titles, legends, scales, Themes, colours as well as removing series.
After the editor has closed can I query the Tchart such that I can find out whether anything within the chart has been modified? Is there a flag set for example. If I know something has changed I can then prompt the user (when he is closing the application) to save changes.
Re: Is there a "Change" Flag for Teechart?
Posted: Thu Jun 10, 2010 9:13 am
by yeray
Hi Dave,
There isn't a flag to check it right now. However, we are investigating if we can propose a solution to do it manually.
We'll be back here asap.
Re: Is there a "Change" Flag for Teechart?
Posted: Thu Jun 10, 2010 1:51 pm
by yeray
Hi Dave,
First, note that this is a feature request already in the wish list to be implemented in future releases (TV52011331).
In the meanwhile here it is an example of how you could do it manually, saving the chart into a MemoryStream before opening the editor, saving the chart once the editor is closed, and compare both memorystreams:
Code: Select all
private void InitializeChart()
{
tChart1.Aspect.View3D = false;
Steema.TeeChart.Styles.Bar bar1 = new Steema.TeeChart.Styles.Bar(tChart1.Chart);
bar1.FillSampleValues();
bar1.XValues.DataMember = "X";
bar1.YValues.DataMember = "Bar";
}
void EditorButton1_Click(object sender, EventArgs e)
{
byte[] tmpbuffer1, tmpbuffer2;
tmpbuffer1 = ExportToByte(tChart1);
tChart1.ShowEditor();
tmpbuffer2 = ExportToByte(tChart1);
if (!CompareByteArrays(tmpbuffer1, tmpbuffer2))
{
System.Windows.Forms.SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.DefaultExt = tChart1.Export.Template.FileExtension;
saveFileDialog1.FileName = tChart1.Name + "." + saveFileDialog1.DefaultExt;
saveFileDialog1.Filter = Steema.TeeChart.Texts.TENFilter;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
tChart1.Export.Template.Save(saveFileDialog1.FileName);
}
}
}
private byte[] ExportToByte(Steema.TeeChart.TChart chart)
{
System.IO.MemoryStream tmpStream = new System.IO.MemoryStream();
chart.Export.Template.Save(tmpStream);
byte[] tmpbuffer = new byte[tmpStream.Length];
tmpStream.Read(tmpbuffer, 0, (int)tmpStream.Length);
return tmpbuffer;
}
private static bool CompareByteArrays(byte[] data1, byte[] data2)
{
if (data1 == null && data2 == null) return true;
if (data1 == null || data2 == null) return false;
if (data1.Length != data2.Length) return false;
for (int i = 0; i < data1.Length; i++)
{
if (data1[i] != data2[i]) return false;
}
return true;
}
Re: Is there a "Change" Flag for Teechart?
Posted: Thu Jun 10, 2010 2:09 pm
by 13050364
Thanks Yeray I will try this out.
Re: Is there a "Change" Flag for Teechart?
Posted: Thu Jun 10, 2010 4:03 pm
by 13050364
Yeray have you tested this example?
It seems to work almost every time when the editor is displayed and closed. ie. it correctly identifies when changes have been made and when no changes have been made.
However the exception is the very first time the editor is displayed and closed. In this case it always records changes have been even when there is no change.
Im not sure what is happening. The arrays should be reset every time, its a bit bizarre.
Re: Is there a "Change" Flag for Teechart?
Posted: Thu Jun 10, 2010 4:19 pm
by 13050364
Im getting it to work correctly ALL times if I do the following before calling the editor. Dont know if something is being cleared somewhere but it works
byte[] tmpbuffer1, tmpbuffer2;
tmpbuffer1 = ExportToByte(tChart1);
tmpbuffer2 = ExportToByte(tChart1);
Re: Is there a "Change" Flag for Teechart?
Posted: Fri Jun 11, 2010 9:33 am
by yeray
Hi Dave,
We found that the first time the Serialization doesn't serialize DataMembers. That's the reason why I added the following lines in the InitializeChart process, before the first call to the comparison:
Code: Select all
bar1.XValues.DataMember = "X";
bar1.YValues.DataMember = "Bar";
Re: Is there a "Change" Flag for Teechart?
Posted: Fri Jun 11, 2010 2:03 pm
by yeray
Hi Dave,
In addition to above, the problem was that the Serialization accesses the DataSource, and when the GetDataSource is accessed the DataMembers are set. This may involve in a different serialization the first time.
We've included a check that ensures the DataSource won't be serialized if it's null so the workaround explained in my last post won't be needed. This will be included in the next maintenance release.