Serialize Reportcontrol state to file? |
Post Reply |
Author | |
unknow
Groupie Joined: 14 January 2009 Location: Belgium Status: Offline Points: 62 |
Post Options
Thanks(0)
Posted: 29 July 2009 at 4:40pm |
Hi. I am developping a MDI application where the document view is a reportcontrol;
I don't want to store the reportcontrol state in the registry because it will be possible to set the column names, orders, size etc... for each document.
So instead, I would like to store/restore the reportcontrol state from the document itself, I mean storing the state in a section of my document file.
Can it be done ? and if possible in text/XML format, not binary;
Thankx!!
|
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
Sure you can do it yourself - see void CReportSampleView::LoadReportState()
|
|
unknow
Groupie Joined: 14 January 2009 Location: Belgium Status: Offline Points: 62 |
Post Options
Thanks(0)
|
I found that the CReportSampleView class from the ReportSample sample already has the code to serialize to/from file;
void CReportSampleView::LoadReportState()
{ #ifdef XML_STATE CXTPPropExchangeXMLNode px(TRUE, 0, _T("ReportControl")); if (!px.LoadFromFile(_T("c:\\ReportControl.xml"))) return; But it saves/restore from a single xml file; I would like to save/restore the reportcontrol state from a portion of my XML document, for example it could be placed after my XML data.
So now the question is: can I serialize the reportcontrol state from an already opened file?
Thankx!
|
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
Sure - void LoadReportState(); and void SaveReportState(); app-level functions. You can make your own ones and select needed settings for load and restore and use your own storage mechanism
|
|
unknow
Groupie Joined: 14 January 2009 Location: Belgium Status: Offline Points: 62 |
Post Options
Thanks(0)
|
Thanks for your reply and sorry if I'm a bit "slow" but can I just use the code provided in the CReportSampleView::LoadReportState + CReportSampleView::SaveReportState and read/write from an already opened file in text mode ? The idea would be to call this code from the document serialize routine;
|
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
I think you can - may be with small modifications.
|
|
unknow
Groupie Joined: 14 January 2009 Location: Belgium Status: Offline Points: 62 |
Post Options
Thanks(0)
|
Hi! I found that the CXTPPropExchangeXMLNode class provides LoadFromFile and SaveToFile features;
It also provides a LoadFromString feature, but NO "SaveToString" ??
I would like to serialize the ReportControl state in XML format as part of my document, so it would be much easier for me to load/save from a CString.
How can I save the reportstate to a CString ?
|
|
mdoubson
Senior Member Joined: 17 November 2008 Status: Offline Points: 1705 |
Post Options
Thanks(0)
|
You can use different ways: e.g.
derive your own MyPropExchangeXMLNode from CXTPPropExchangeXMLNode,
or
use CXTPPropExchangeXMLNode and call SaveToFile with temp_file_name generated by Windows API and writable under any user restriction, read generated file to your string and after delete this temporary file....
or
use prev idea but with memory file(?)
or ask Oleg to extend base class CXTPPropExchangeXMLNode
or try to use this advice from http://www.tech-archive.net/Archive/VC/microsoft.public.vc.mfc/2004-08/1568.html :
> The save method in IXMLDOMDocument is defined in MSDN as:
> > HRESULT save(VARIANT destination); > > destination [in] : The type of object to save. This object can represent a file name, an ASP Response object, an XML document object, or a custom > object that supports persistence. See Remarks for more information. > > Remarks: > Any other custom COM object that supports QueryInterface for IStream, IPersistStream, or IPersistStreamInit can also be provided here, and the > document will be saved accordingly. In the IStream case, the IStream Write method will be called as it saves the document; in the IPersistStream case, > IPersistStream Load will be called with an IStream that supports the Read, > Seek, and Stat methods. > > If I want to save the XML document to memory, how should I proceed? What value should be assigned to destination? Create a COM object that implements the IStream interface. When you call IXMLDOMDocument::save, put your object's IUnknown pointer into the VARIANT's punkVal member. In your COM object, you must implement the methods of the IStream interface. When your Write method is called, you can do anything you want with the bytes that are passed to it, including stuffing them into a memory buffer. |
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hi,
Use px.GetXML() string to get Node as string.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |