IMPLEMENT_SERIAL (Changing the Base Class)

This might be a stupid question, or it could be incredibly
insightful... ...but hope it's not the latter.

I have a class that is probably about 3 levels away from the CObject
class.  Like this:
     CObject->ClassA->ClassSerialMe

Currently I serialize this object with the usual:
     IMPLEMENT_SERIAL(ClassSerialMe, ClassA, VERSIONABLE_SCHEMA | 1 )

What would I need to do to change the base class of ClassA to:
     CObject->ClassB->ClassSerialMe

And use the Serialize functionailty to a differnt version:
     IMPLEMENT_SERIAL(ClassSerialMe, ClassB, VERSIONABLE_SCHEMA | 2 )

I can't just change the base class(version one would not work) and I
cant declare IMPLEMENT_SERIAL twice.  I could declare a new class
"ClassSerial02" and copy the data over but that would be ugly.

What am I missing?

Thanks,
Eric
closed(underscore)cell(underscore)foam(at)hotmail(dot)com

0
8/22/2005 7:10:43 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
795 Views

Similar Articles

[PageSpeed] 58

closed_cell_foam@hotmail.com wrote:
> This might be a stupid question, or it could be incredibly
> insightful... ...but hope it's not the latter.
>
> I have a class that is probably about 3 levels away from the CObject
> class.  Like this:
>      CObject->ClassA->ClassSerialMe
>
> Currently I serialize this object with the usual:
>      IMPLEMENT_SERIAL(ClassSerialMe, ClassA, VERSIONABLE_SCHEMA | 1 )
>
> What would I need to do to change the base class of ClassA to:
>      CObject->ClassB->ClassSerialMe
>
> And use the Serialize functionailty to a differnt version:
>      IMPLEMENT_SERIAL(ClassSerialMe, ClassB, VERSIONABLE_SCHEMA | 2 )

Seems like you have a problem here.

If all you want to do is add serialization functions, then you can
modify the serialization including the old V1 serialization to include
the new V2 serialization, and to check the Schema version upon loading.

0
darsant (187)
8/22/2005 8:13:37 PM
But what about the change of the base class of "ClassSerialMe" from
"ClassA" to "ClassB"?  For an added bonus both "ClassA" and "ClassB"
are derived from the same class,  Let's say "ClassD", that is derived
from CObject.

CObject::ClassD::ClassA::ClassSerializeMe

I want to change it to:
CObject::ClassD::ClassB::ClassSerializeMe

I am changing the type which I think means I am up the creek?  If I
change the base type that means that the entire structure of ClassA is
saved in earlier versions of "ClassSerializeMe".  On reload it would
have to have that knowledge.  But if I change the "ClassSerialize" base
type that data is clearly not there and it can't be recovered because
the base type of my serialized object has changed in the code.

I imagine I could do some fancy casting stuff but that starts getting
dangerous and ugly.

I imagine that I am going to have to create a second class and copy the
old data over into the new derived class.  UGLY!

Thanks Much.

0
8/22/2005 8:32:51 PM
Tried just changing the base class and when it tries to load the new
base class the app throws an error because it can't load desired data
from the old class data.  Looks Like its time to create a new class.

0
8/22/2005 8:54:41 PM
closed_cell_foam@hotmail.com wrote:
> But what about the change of the base class of "ClassSerialMe" from
> "ClassA" to "ClassB"?  For an added bonus both "ClassA" and "ClassB"
> are derived from the same class,  Let's say "ClassD", that is derived
> from CObject.
>
> CObject::ClassD::ClassA::ClassSerializeMe
>
> I want to change it to:
> CObject::ClassD::ClassB::ClassSerializeMe

Sounds like you have a problem with inheritance. If you want to make
serialization for different classes with a similar base, you should
have at least two different routines.

For Example, in the case you specified, you would want 3 serialization
functions, and all 3 implemented as serialized:

ClassD.Serialize
ClassA.Serialize
and
ClassB.Serialize.

Now, what you'd do is handle all of D's serialization in D. When you
have an inherited class such as A or B, the first thing you do would be
to call Serialize for ClassD, and then handle the specific A or B
serialization.

Using this method you don't need an additional class each time, you
simply add call the base members serialization and then add whatever
you need to for the new information.

0
darsant (187)
8/22/2005 9:02:35 PM
I definately do have an inheritance problem.

Lets say my code looks something like this.  (Just trying to phrase it
another way)

//////////////// Base Class Decalaration  ////////////////////////////
class BaseClass : public CObject
{
  public:
    // An integer that holds Data
    int m_nMyInt;

    // serialization code
    virtual void Serialize(CArchive& ar);
}

//////////////// Base Class Implementation  /////////////////////////
IMPLEMENT_SERIAL(BaseClass , CObject, VERSIONABLE_SCHEMA | 1)

// Serialize for base class
void BaseClass::Serialize(Carchive& ar)
{
	CObject::Serialize(ar);

 // Set the schema version for checking data integrity.
    m_nSchemaVersion = ar.GetObjectSchema();


    // Note: the m_nImageOffset data member is not serialized
    // because it is set by the constructor and does not change.
    if ( ar.IsStoring() )
    {
        // save code here
        ar << m_nMyInt;
    }
    else
    {
        ar >> m_nMyInt;
    }

}


//////////////// ClassA Decalaration  ////////////////////////////
class ClassA : public BaseClass
{
  public:
    // An integer that holds Data
    int m_nScore;

    // serialization code
    virtual void Serialize(CArchive& ar);
}

//////////////// ClassA Implementation  /////////////////////////
IMPLEMENT_SERIAL(ClassA , BaseClass, VERSIONABLE_SCHEMA | 1)

// Serialize for base class
void ClassA::Serialize(Carchive& ar)
{
    BaseClass::Serialize(ar);

    if ( ar.IsStoring() )
    {
        // save code here
        ar << m_nScore;
    }
    else
    {
        ar >> m_nScore;
    }
}

//////////////// ClassB Decalaration  ////////////////////////////
class ClassB : public BaseClass
{
  public:
    // An integer that holds Data
    int m_nNumber;

    // serialization code
    virtual void Serialize(CArchive& ar);
}

//////////////// ClassB Implementation  /////////////////////////
IMPLEMENT_SERIAL(ClassB , BaseClass, VERSIONABLE_SCHEMA | 1)

// Serialize for base class
void ClassB::Serialize(Carchive& ar)
{
    BaseClass::Serialize(ar);

    if ( ar.IsStoring() )
    {
        // save code here
        ar << m_nNumber;
    }
    else
    {
        ar >> m_nNumber;
    }
}

//////////////// ClassC Decalaration  ////////////////////////////
class ClassC : public ClassA
{
  public:
    // An integer that holds Data
    int m_nAltitude;

    // serialization code
    virtual void Serialize(CArchive& ar);
}

//////////////// ClassB Implementation  /////////////////////////
IMPLEMENT_SERIAL(ClassC , ClassA, VERSIONABLE_SCHEMA | 1)

// Serialize for base class
void ClassC::Serialize(Carchive& ar)
{
    ClassA::Serialize(ar);

    if ( ar.IsStoring() )
    {
        // save code here
        ar << m_nAltitude;
    }
    else
    {
        ar >> m_nAltitude;
    }
}

Now if I wanted to change the derived class "ClassC" from being derived
from "ClassA" to "ClassB"  That would fail when the app tries to reload
an older version of this object.  When the file is loaded it will fail
when it tries to read the "ClassB" data where it finds "ClassA" data.
Right?

0
8/23/2005 12:45:28 PM
closed_cell_foam@hotmail.com wrote:
> Now if I wanted to change the derived class "ClassC" from being derived
> from "ClassA" to "ClassB"  That would fail when the app tries to reload
> an older version of this object.  When the file is loaded it will fail
> when it tries to read the "ClassB" data where it finds "ClassA" data.
> Right?

Yes this will fail. In order to prevent something like this you have to
be backwards compatible.

ClassC must reference ClassA. Schema was made to allow additions to the
class, but if you still wish to read old data, you must create a new
ClassD to be inherited from ClassB, at least on the loading side. This
way the loading from a serialized data source is able to recognize th e
old ClassC as well as the new ClassC. By changing the inheritance you
are messing with the assumptions that you made when you stored the
object (Object was stored with relationship A-->C, but then you try to
load it and it loads B-->C, this is not what was intended)

It may not fail, it may fail, it's hard to say. It's not specifically
spelled out in the docs, so it's in the land of undefined behavior. If
ClassB and ClassA are similar enough, it may work, or it may not.

That brings us back to the original question:

Why are you changing the base class of an object so freely? Going from
A-->C to B-->C should not be something that should be able to just
simply be switched. If you want to store different information, you
shouldn't be replicating so much work, as the information that is the
same in B and A should be in BaseClass.

Josh McFarlane

0
darsant (187)
8/23/2005 7:13:08 PM
Reply:

Similar Artilces:

Changes subject line
When I receive a word doc from one particular person, open it and make modifications and send back as a reply, it changes the subject line to a very old message that has been deleted for months. It always changes to the same old subject line and only happens when sending to one specific person. ...

can "if" formula be used to change cell formatting?
hello, can cell formatting conditionally change based on what the cell value is by using an "if" formula? basically what i am after is: if value in cell A1="x" then cell A1 font color is red, else cell A1 font color is black. if an x is input, it turns red, if anything else is input, it is black. i do not want to do this with a macro since i want the cell formatting to change immediately upon editing the cell value. can this be done? thanks for your time! karen --- Message posted from http://www.ExcelForum.com/ Hi you may have a look at 'Format - Conditional...

Daylight Savings Changes for Commonwealth Games
Dear ALL, I am still on NT4 domain. My Exchange 5.5 servers & OWA 5.5 server runs on Windows 2000 operating system. As far as I know, there is no patch availabe for Exchange 5.5. How? Am I going to face problem if not doing anything? What happen if the user apply the patch on their workstation? Please advise, thanks. On Sun, 19 Mar 2006 16:16:26 -0800, seeker01 <seeker01@discussions.microsoft.com> wrote: >Dear ALL, >I am still on NT4 domain. My Exchange 5.5 servers & OWA 5.5 server runs on >Windows 2000 operating system. As far as I know, there is no patch availab...

save changes when no changes made
When I go to close an Excel document, I am asked about saving changes even though none have been made. I have already searched this question here and every suggestion has not helped. I do not have any macros in the workbook, no links to any other workbooks and it does not have any functions that may cause this (I know that TODAY(), NOW(), etc.) can cause this. Any suggestions to find what I have stuck in the file or a setting wrong? I have Excel 2002 If the workbook was created in an earlier version of excel, then xl2002 will recalculate it when it opens. And then when you close th...

Change Track Changes Colour
Hi Is it possible to change the colour that Excel 2003 Track Changes appears in? It's currently showing up as navy which is difficult to identify against black. Thanks ...

Jscript
Hi I want to change the background color of a field when certain conditions are true. Can someone please advise me what the syntax is? I am currently using the code below which only makes the border colour to be red. I would really appreciate some help. var r = crmForm.all.new_field.DataValue; var d = crmForm.all.new_field1.DataValue; if (r!= null) if (r<d) { crmForm.all.new_field.style.backgroundColor = "#FF0000"; crmForm.all.new_field.Color = "#FF0000"; } Regards Snow White Try replacing crmForm.all.new_field.style.backgroundColor = "#FF0000"; With...

How to change saving from My documents to another place?
Every time I save my work I am directed to My Documents. I want to save in another place. How do I do that? Blair What version of Publisher are you using? "Blair" <darrach@coille.com> wrote in message news:e0wN8DtAGHA.216@TK2MSFTNGP15.phx.gbl... > Every time I save my work I am directed to My Documents. I want to save in > another place. How do I do that? > Blair Tools, Options, general tab, change the location... -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "Blair" <darrach@coille.com&g...

Changing the colour of a comment?
Hi I want to know in Excel 2003, when I enter in a comment the cell is flagged with a red indicator in the top right hand corner. Is there a way that I can change the colour of the indicator? Thanks Rob Rob, no need to post to more than one group, must people look at all of them, I don't think this is possible -- Paul B Always backup your data before trying something new Please post any response to the newsgroups so others can benefit from it Feedback on answers is always appreciated! Using Excel 2002 & 2003 "Rob" <rbotterill@hspg.com> wrote in message new...

CArchive error in IMPLEMENT_SERIAL
Hi, I working in a project in VC++6.0 .I am using nearly 20 classes , in that nearly 5 class are derived from Cobject .I have implemented serialization . When I use object of one class (derived from Cobject ) in another .I got a error saying that Error C2679: binary '>>' : no operator defined which takes a right- hand operand of type 'class CAlertSent *' (or there is no acceptable conversion) For this line : archive >> nextSentAlert; So I added this line.in the file where I am using that CAlertSent object. IMPLEMENT_SERIAL(CAlertSent,CObject,VERSIONABLE_SCHEM...

Change in account's form automatically updates contact's form
Hello, How to make so that during a change (i.e address) in the account's form that automatically updates the change in the contact's form associated on this account? You need a callout to do it. Look at http://www.stunnware.com/crm2/topic.aspx?id=Callout1 which is exactly what you're looking for. -- Michael Web: http://www.stunnware.com/crm2 Feed: http://www.stunnware.com/crm2/atom.aspx ---------------------------------------------------------- "fabrice" <fabrice@discussions.microsoft.com> schrieb im Newsbeitrag news:2288C155-5E58-459B-9CBD-035036B...

An example from a book is method NewFloorRequest in the right class
Hello! Below is an example from a book. The books is position method NewFloorRequest in class Person. What is your opinion about that in this example ? How should I think here ? If I think who is pushing the button then it's the Person and so it should be in class Person. I also mean that it belong more logically to class Elevator. Can somebody give me a guideline how I should think when trying to find a suitable class for method NewFloorRequest ? using System; class Elevator { private int currentFloor = 1; private int requestedFloor = 0; private totalFl...

applying changes across pages
Newbie to Publisher Question Follows :) : How do I edit ....let's say the Home page of a premade website in publisher and remove an object and have that change apply to all the pages. I seem to be able to change the contents of the premade pub site text box and have it apply to all the pages on the site . If I delete the Object it only applies to that one page . ANY HELP GREATLY APPRECIATED! Rich K Please refer to your posting in the correct forum of webdesign. FYI, one post in one group is sufficient. -- David Bartosik - MS MVP for Publisher help: www.davidbartosik.com enter t...

OWA 2003 Change Password Issues
I am working with: Windows 2003 Standard SP1 Exchange 2003 Enterprise SP1 I have recently installed the above products on a new server and the install went great. No errors, no issues. All is working well except for the change password function in OWA. I turned on the change password feature and it appeared as it should. The first thing I noticed is that when I selected the change password button, the domain would not be automatically populated like it should and I could not change my password. Everything I found on the Internet pointed me toward hot fix 833734. I contacted Micros...

When i change ComboBox, my textboxes should change accordingly, ho
I have a form with 4 items. -ID -Name -Nationality -Department When i change ComboBox (ID) i want my textboxes to change accordingly to show thier corresponding Name, Nationality and Department. How can this be done using a form. Please let me know the steps. Thanks a lot exerpt ! -- Allen Phailat Wongakanit "ali" <ali@discussions.microsoft.com> wrote in message news:9C0F44AC-6DC4-441F-830C-02B14DF8EC6B@microsoft.com... >I have a form with 4 items. > > -ID > -Name > -Nationality > -Department > > When i change ComboBox (ID) > > i want my ...

Code to change part of a formula across worksheets
Hi all - I hope someone can help with this... I have formulas that include links (not hyperlinks) in their calculations e.g. Cell A5 formula is: ='C:\Documents and Settings\Bob.JOB-Bob\My Documents\Bob Personal\Inventors\Meetings\[XClient Plan for Restructuring and Rebudgeting as at 06_10_09.xls]Detailed Report'!$U$18+$C83 I need a macro to prompt the user to enter the OLD workbook name into an input box e.g. [XClient Plan for Restructuring and Rebudgeting as at 06_10_09.xls] The code looks for all cells with that string and then replaces it with the new workbook na...

how to change PROPSHEETPAGE_V3 to V2?
When I define _WIN32_WINNT to 0x0500, the struct PROPSHEETPAGE is suppose to be PROPSHEETPAGEA_V2. But when I'm debugging, I find it is using PROPSHEETPAGEA_V3. Why? Should I define other flags to carry out it? Thanks! ...

Change name?
How do I change the name that is in the microsoft.public.excel.misc column "From". Thanks, Roger Since you use outlook express you have to do it there tools>account and select the news account in question and click properties then change the name -- Regards, Peo Sjoblom "Roger Bedford" <rb10@canada.com> wrote in message news:O1lwmwoTFHA.4056@TK2MSFTNGP15.phx.gbl... > How do I change the name that is in the microsoft.public.excel.misc column > "From". > > Thanks, > > Roger > ...

Sudden change in "Sent" folder
Yesterday, my "Sent" folder showed sent messages listed by the addressee, that is, the first column was "To." Suddenly this morning, it says "From" and I have no idea how to find a message by the recipient! This is a major inconvenience! Whahoppen??? You probably changed the view on your Sent Items folder by mistake. The default view for the Sent Items folder is "Sent To". Change it via View | Current View, or enable the Advanced toolbar and use the Views dropdown box. -- Jocelyn Fiorello MVP - Outlook *** Messages sent to my e-mail addres...

IMPLEMENT_SERIAL for nested classes
Anyone aware of a way to get serialization to work for nested classes? I'm having a tough time figuring out how to properly utilize the IMPLEMENT_SERIAL for a class which is nested. class MyOuter { class MyInner { }; }; ...

Money 2004
Does anyone know if I can customize the charts or reports on the homepage. For example the income vs expense report is based on all accounts and categories. I would like to customeize this graph. Any help is appreciate. Thanks ...

Using Formulas to Change Colors
Can you use formulas to change the shadow of the cell when certain conditions are met? I am very good using Excel, but have never tried this and I cannot find any documentation. So, I think that it just cannot be done. Dave Hi Dave, Format>Conditional Formatting -- Kind regards, Niek Otten Microsoft MVP - Excel "Dave Jacoby" <dmjacoby@davejacoby.com> wrote in message news:%1Tmh.14861$U12.10061@bignews1.bellsouth.net... | Can you use formulas to change the shadow of the cell when certain | conditions are met? I am very good using Excel, but have never tried th...

Change info order
Hi, I need to reverse this info, please!!. This is the original DATA A B C D 1 C=D3DIGO 74475 74471 74469 2 1010046 2 5 1 3 1010800 0 1 0 4 1010169 5 1 0 5 1011031 4 2 1 6 1010111 0 0 5 And I need this to show up A B C D 1 C=D3DIGO CANTIDAD LOCAL 2 1010046 2 74475 3 1010169 ...

Publisher 2007 Print Setup Margins & Gaps change when changing pri
I'm trying to print business cards on a printer that is not my default printer. In the Print Setup | More Print Options dialogue box I have the margins set as follows when my default printer is selected: Side Margin: 0.7" Top Margin: 0.44" Horizontal Gap: 0" Vertical Gap: 0" However, when I switch to my color printer (not the default printer) the margins and gaps change. I cannot find a way to save them, and I can't change my default printer as it's set in the group policy for my system. It's amazingly tedious to change all four settings every time I ...

Change Track Changes default options
Track Changes defaults to tracking format changes as well as substantive ones. Is there a way to change the default to not track format changes so it doesn't have to be changed each time I use Track Changes? You can try turning it off in the normal.dotm template, and some people find that it sticks. I find that it turns itself back on anyway. On Dec 9, 11:15=A0am, coffent <coff...@discussions.microsoft.com> wrote: > Track Changes defaults to tracking format changes as well as substantive > ones. =A0Is there a way to change the default to not track format changes= ...

Price Change on the Customization Table
Hi, We have a customization application in the GP. One of the major function is to provide more flexible pricing, which will set a different price for different customer. But when it comes to price change, it takes way long to change the price because we have to do them for every single customer. Is there a better way to do it? I am thinking of Integration Manager, but IM can not handle the custimization table. We have a Excel sheet to record the price change, I am thinking of a way that can update the table based on the Excel spreadsheet. Basically the info on the spreadsheet...