Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - Serialize Reportcontrol state to file?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Serialize Reportcontrol state to file?

 Post Reply Post Reply
Author
Message
unknow View Drop Down
Groupie
Groupie
Avatar

Joined: 14 January 2009
Location: Belgium
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote unknow Quote  Post ReplyReply Direct Link To This Post Topic: Serialize Reportcontrol state to file?
    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!!
 
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 31 July 2009 at 11:44am
Sure you can do it yourself - see void CReportSampleView::LoadReportState()
Back to Top
unknow View Drop Down
Groupie
Groupie
Avatar

Joined: 14 January 2009
Location: Belgium
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote unknow Quote  Post ReplyReply Direct Link To This Post Posted: 10 August 2009 at 6:44pm
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!
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 10 August 2009 at 6:46pm
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
Back to Top
unknow View Drop Down
Groupie
Groupie
Avatar

Joined: 14 January 2009
Location: Belgium
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote unknow Quote  Post ReplyReply Direct Link To This Post Posted: 11 August 2009 at 3:14pm

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;
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 11 August 2009 at 3:24pm
I think you can - may be with small modifications.
Back to Top
unknow View Drop Down
Groupie
Groupie
Avatar

Joined: 14 January 2009
Location: Belgium
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote unknow Quote  Post ReplyReply Direct Link To This Post Posted: 23 August 2009 at 11:45am
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 ?
Back to Top
mdoubson View Drop Down
Senior Member
Senior Member
Avatar

Joined: 17 November 2008
Status: Offline
Points: 1705
Post Options Post Options   Thanks (0) Thanks(0)   Quote mdoubson Quote  Post ReplyReply Direct Link To This Post Posted: 24 August 2009 at 12:34am
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
> 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.
 
 
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 25 August 2009 at 5:31am
Hi,
 
Use px.GetXML() string to get Node as string.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.156 seconds.