From: Elizabeta on
Hello

How can I serialize Mfc template dialog class , I can't use DECLARE_SERIAL
and IMPLEMENT_SERIAL for this . I noticed that IMPLEMENT_SERIAL_T macro
exist, but it is not documented and there is no corresponding
DECLARE_SERAIL_T.

Thanks
From: Giovanni Dicanio on
Elizabeta ha scritto:

> How can I serialize Mfc template dialog class , I can't use DECLARE_SERIAL
> and IMPLEMENT_SERIAL for this . I noticed that IMPLEMENT_SERIAL_T macro
> exist, but it is not documented and there is no corresponding
> DECLARE_SERAIL_T.

I've never seen an MFC serialization of a CDialog-derived class.
I don't know if it is possible.

What would you like to do?
Could you please clarify your goal?

If your dialog is used to entry/show some data, you may want to create a
C++ class derived from CObject that stores that data (e.g. a CPerson,
with name, surname, address, etc.), and use DECLARE_SERIAL and
IMPLEMENT_SERIAL on this non-GUI class.

However, I think that in these days there are better techniques for
serializing data, like using XML, instead of MFC serialization.

If you are interested in XML, you may find this CMarkup MFC class freely
available on CodeProject useful:

http://www.codeproject.com/KB/cpp/markupclass.aspx


HTH,
Giovanni
From: Elizabeta on
>>If your dialog is used to entry/show some data, you may want to create a
>>C++ class derived from CObject that stores that data (e.g. a CPerson,
>>with name, surname, address, etc.), and use DECLARE_SERIAL and
>>IMPLEMENT_SERIAL on this non-GUI class.

Ok lets say that for Dialog template classes I can do your suggestion, thanks.

But what about template classes that are not dialogs, so I want to
reformulate my question :
How to use macros like DECLARE_SERIAL and IMPLEMENT_SERIAL with c++ template
classes derived from CObject ?
From: Giovanni Dicanio on
Elizabeta ha scritto:

> Ok lets say that for Dialog template classes I can do your suggestion, thanks.

You are welcome.

> But what about template classes that are not dialogs, so I want to
> reformulate my question :
> How to use macros like DECLARE_SERIAL and IMPLEMENT_SERIAL with c++ template
> classes derived from CObject ?

I'm not sure if DECLARE_SERIAL and IMPLEMENT_SERIAL macros work well
with C++ template classes.

However, you may want to learn from what MFC developers did in a similar
case. If my understanding is correct, you would like to define a C++
template class, derived from CObject, and with support for MFC
serialization.

There are some examples of these classes already defined in MFC, e.g.
CArray is an MFC template class (CArray<TYPE, ARG_TYPE>), derived from
CObject, and with support with serialization.

You may want to open <afxtempl.h> file and read the implementation of
CArray, in particular the CArray<TYPE, ARG_TYPE>::Serialize() method.
(I think that their approach is to not use DECLARE_SERIAL and
IMPLEMENT_SERIAL macros, though).

(However, I still think that other options like XML should be used
instead of MFC serialization, IMHO.)

Giovanni
From: Joseph M. Newcomer on
It wouldn't make sense to serialize a dialog. Nor does it make much sense to have a
dialog class created by a template. If you need some kind of templating, it most likely
applies to data *within* the dialog, and therefore you should create a templated class to
hold your data.

I do not believe you can derive a template class from CObject, because of how the macros
work. You did not say which version of VS you are using.

Generally, MFC serialization is among the worst possible ways to implement persistent
memory of information. It is needlessly complex (in spite of the claims otherwise)
because it is exceptionally fragile under what is known as "schema migration". Change
anything in the class, such as adding or deleting a member variable, or changing its type,
and all existing files are rendered unreadable. I would suggest avoiding it entirely. I
tend to use either simple text files or XML files if I have complex structured data. I
have studiously avoided using MFC serialization for 15 years (we had implemented the
equivalent of MFC serialization in 1977 and knew exactly what was wrong with it, and when
I saw MFC serialization, all I could do was shake my head and say "how could they DO
something this bad when we knew almost 20 years ago [I looked at this in 1996] that it
cannot work". Our sollution, by the way, was to have an XML file we wrote out, along with
the binary. If the binary file had a different version than the program could read, we
ignored the binary form of the file and read the XML form [yes, I helped invent XML in
1977; it looked much better than the current XML, was more powerful, and the second
generation, done ca. 1980, and known as IDL, was even better. But it was not yet time to
build steam engines, so our work was ignored and then badly reinvented by the XML
designers. We documented our work in a 1989 book].
joe

On Fri, 4 Sep 2009 02:06:01 -0700, Elizabeta <Elizabeta(a)discussions.microsoft.com> wrote:

>Hello
>
>How can I serialize Mfc template dialog class , I can't use DECLARE_SERIAL
>and IMPLEMENT_SERIAL for this . I noticed that IMPLEMENT_SERIAL_T macro
>exist, but it is not documented and there is no corresponding
>DECLARE_SERAIL_T.
>
>Thanks
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm