Home All Groups Group Topic Archive Search About

How to back up an object...

Author
11 Apr 2005 2:39 PM
Simon Verona
I have a custom class inherited from a third party control.

Within the class, I need to make a backup copy of the class so that I can
change the properties (font size etc) for printing.

So, I'm using code such as...

    Dim backup as dmsreport =me
    backup.font=newfont
    backup.print
    etc etc


I was expecting this not to change any of the parameters of my original
object, however I find that "backup" is created simply as a reference to
"me" and therefore "me" contains all the updates I subsequently make to the
backup.

How do I make a copy of the object so that I can work on the copy without
changing the original?

Hope that this makes sense!

Regards
Simon

Author
11 Apr 2005 2:59 PM
JohnFol
What happens if you use the New keyword?


Show quoteHide quote
"Simon Verona" <n***@aphroditeuk.com> wrote in message
news:eo1ASRqPFHA.2584@TK2MSFTNGP15.phx.gbl...
>I have a custom class inherited from a third party control.
>
> Within the class, I need to make a backup copy of the class so that I can
> change the properties (font size etc) for printing.
>
> So, I'm using code such as...
>
>    Dim backup as dmsreport =me
>    backup.font=newfont
>    backup.print
>    etc etc
>
>
> I was expecting this not to change any of the parameters of my original
> object, however I find that "backup" is created simply as a reference to
> "me" and therefore "me" contains all the updates I subsequently make to
> the backup.
>
> How do I make a copy of the object so that I can work on the copy without
> changing the original?
>
> Hope that this makes sense!
>
> Regards
> Simon
>
Author
11 Apr 2005 3:38 PM
Simon Verona
John

I did try splitting the line into :

dim backup as new dmsreport
backup=me

but this seems to have the same affect.

Regards
Simon
Show quoteHide quote
"JohnFol" <OutlookExpr***@WibbleObbble.Com> wrote in message
news:ahw6e.17857$il.15981@newsfe5-win.ntli.net...
> What happens if you use the New keyword?
>
>
> "Simon Verona" <n***@aphroditeuk.com> wrote in message
> news:eo1ASRqPFHA.2584@TK2MSFTNGP15.phx.gbl...
>>I have a custom class inherited from a third party control.
>>
>> Within the class, I need to make a backup copy of the class so that I can
>> change the properties (font size etc) for printing.
>>
>> So, I'm using code such as...
>>
>>    Dim backup as dmsreport =me
>>    backup.font=newfont
>>    backup.print
>>    etc etc
>>
>>
>> I was expecting this not to change any of the parameters of my original
>> object, however I find that "backup" is created simply as a reference to
>> "me" and therefore "me" contains all the updates I subsequently make to
>> the backup.
>>
>> How do I make a copy of the object so that I can work on the copy without
>> changing the original?
>>
>> Hope that this makes sense!
>>
>> Regards
>> Simon
>>
>
>
Author
11 Apr 2005 3:44 PM
JohnFol
ok, I created a new form called Form1 with a single button on it,. The code
is as follows

Dim MyCopyForm As New Form1

MyCopyForm.BackColor = BackColor.Bisque

MyCopyForm.Show()



This gives me the copy I was after. I think the problem you are having is
you explicitly set the "copy" to point to the original. Just try

Dim backup as dmsreport
backup.font=newfont
backup.print








Show quoteHide quote
"Simon Verona" <n***@aphroditeuk.com> wrote in message
news:OZdTPyqPFHA.2356@TK2MSFTNGP14.phx.gbl...
> John
>
> I did try splitting the line into :
>
> dim backup as new dmsreport
> backup=me
>
> but this seems to have the same affect.
>
> Regards
> Simon
> "JohnFol" <OutlookExpr***@WibbleObbble.Com> wrote in message
> news:ahw6e.17857$il.15981@newsfe5-win.ntli.net...
>> What happens if you use the New keyword?
>>
>>
>> "Simon Verona" <n***@aphroditeuk.com> wrote in message
>> news:eo1ASRqPFHA.2584@TK2MSFTNGP15.phx.gbl...
>>>I have a custom class inherited from a third party control.
>>>
>>> Within the class, I need to make a backup copy of the class so that I
>>> can change the properties (font size etc) for printing.
>>>
>>> So, I'm using code such as...
>>>
>>>    Dim backup as dmsreport =me
>>>    backup.font=newfont
>>>    backup.print
>>>    etc etc
>>>
>>>
>>> I was expecting this not to change any of the parameters of my original
>>> object, however I find that "backup" is created simply as a reference to
>>> "me" and therefore "me" contains all the updates I subsequently make to
>>> the backup.
>>>
>>> How do I make a copy of the object so that I can work on the copy
>>> without changing the original?
>>>
>>> Hope that this makes sense!
>>>
>>> Regards
>>> Simon
>>>
>>
>>
>
>
Author
11 Apr 2005 4:40 PM
Simon Verona
Well, I could do that, but I was slightly oversimplifying the problem, I
actually change a number of properties, so I thought I could get away with
saving the whole object rather than each property individually...

Regards
Simon
Show quoteHide quote
"JohnFol" <OutlookExpr***@WibbleObbble.Com> wrote in message
news:SXw6e.17955$il.9389@newsfe5-win.ntli.net...
> ok, I created a new form called Form1 with a single button on it,. The
> code is as follows
>
> Dim MyCopyForm As New Form1
>
> MyCopyForm.BackColor = BackColor.Bisque
>
> MyCopyForm.Show()
>
>
>
> This gives me the copy I was after. I think the problem you are having is
> you explicitly set the "copy" to point to the original. Just try
>
> Dim backup as dmsreport
> backup.font=newfont
> backup.print
>
>
>
>
>
>
>
>
> "Simon Verona" <n***@aphroditeuk.com> wrote in message
> news:OZdTPyqPFHA.2356@TK2MSFTNGP14.phx.gbl...
>> John
>>
>> I did try splitting the line into :
>>
>> dim backup as new dmsreport
>> backup=me
>>
>> but this seems to have the same affect.
>>
>> Regards
>> Simon
>> "JohnFol" <OutlookExpr***@WibbleObbble.Com> wrote in message
>> news:ahw6e.17857$il.15981@newsfe5-win.ntli.net...
>>> What happens if you use the New keyword?
>>>
>>>
>>> "Simon Verona" <n***@aphroditeuk.com> wrote in message
>>> news:eo1ASRqPFHA.2584@TK2MSFTNGP15.phx.gbl...
>>>>I have a custom class inherited from a third party control.
>>>>
>>>> Within the class, I need to make a backup copy of the class so that I
>>>> can change the properties (font size etc) for printing.
>>>>
>>>> So, I'm using code such as...
>>>>
>>>>    Dim backup as dmsreport =me
>>>>    backup.font=newfont
>>>>    backup.print
>>>>    etc etc
>>>>
>>>>
>>>> I was expecting this not to change any of the parameters of my original
>>>> object, however I find that "backup" is created simply as a reference
>>>> to "me" and therefore "me" contains all the updates I subsequently make
>>>> to the backup.
>>>>
>>>> How do I make a copy of the object so that I can work on the copy
>>>> without changing the original?
>>>>
>>>> Hope that this makes sense!
>>>>
>>>> Regards
>>>> Simon
>>>>
>>>
>>>
>>
>>
>
>
Author
12 Apr 2005 12:40 AM
Dennis
If the class is a "roll your own", you can add a Copy Property that uses
"PropertyInfo" to copy all of the properties to a new instance of your class.
If not roll your own, you can create a function to copy all the property
values to a new instance of the class.

Show quoteHide quote
"Simon Verona" wrote:

> Well, I could do that, but I was slightly oversimplifying the problem, I
> actually change a number of properties, so I thought I could get away with
> saving the whole object rather than each property individually...
>
> Regards
> Simon
> "JohnFol" <OutlookExpr***@WibbleObbble.Com> wrote in message
> news:SXw6e.17955$il.9389@newsfe5-win.ntli.net...
> > ok, I created a new form called Form1 with a single button on it,. The
> > code is as follows
> >
> > Dim MyCopyForm As New Form1
> >
> > MyCopyForm.BackColor = BackColor.Bisque
> >
> > MyCopyForm.Show()
> >
> >
> >
> > This gives me the copy I was after. I think the problem you are having is
> > you explicitly set the "copy" to point to the original. Just try
> >
> > Dim backup as dmsreport
> > backup.font=newfont
> > backup.print
> >
> >
> >
> >
> >
> >
> >
> >
> > "Simon Verona" <n***@aphroditeuk.com> wrote in message
> > news:OZdTPyqPFHA.2356@TK2MSFTNGP14.phx.gbl...
> >> John
> >>
> >> I did try splitting the line into :
> >>
> >> dim backup as new dmsreport
> >> backup=me
> >>
> >> but this seems to have the same affect.
> >>
> >> Regards
> >> Simon
> >> "JohnFol" <OutlookExpr***@WibbleObbble.Com> wrote in message
> >> news:ahw6e.17857$il.15981@newsfe5-win.ntli.net...
> >>> What happens if you use the New keyword?
> >>>
> >>>
> >>> "Simon Verona" <n***@aphroditeuk.com> wrote in message
> >>> news:eo1ASRqPFHA.2584@TK2MSFTNGP15.phx.gbl...
> >>>>I have a custom class inherited from a third party control.
> >>>>
> >>>> Within the class, I need to make a backup copy of the class so that I
> >>>> can change the properties (font size etc) for printing.
> >>>>
> >>>> So, I'm using code such as...
> >>>>
> >>>>    Dim backup as dmsreport =me
> >>>>    backup.font=newfont
> >>>>    backup.print
> >>>>    etc etc
> >>>>
> >>>>
> >>>> I was expecting this not to change any of the parameters of my original
> >>>> object, however I find that "backup" is created simply as a reference
> >>>> to "me" and therefore "me" contains all the updates I subsequently make
> >>>> to the backup.
> >>>>
> >>>> How do I make a copy of the object so that I can work on the copy
> >>>> without changing the original?
> >>>>
> >>>> Hope that this makes sense!
> >>>>
> >>>> Regards
> >>>> Simon
> >>>>
> >>>
> >>>
> >>
> >>
> >
> >
>
>
>
Author
12 Apr 2005 5:57 AM
Simon Verona
Thanks, I'll have to do that.

Regards
Simon
Show quoteHide quote
"Dennis" <Den***@discussions.microsoft.com> wrote in message
news:13EFB6C4-3B62-4D36-82CE-6D42425BEF40@microsoft.com...
> If the class is a "roll your own", you can add a Copy Property that uses
> "PropertyInfo" to copy all of the properties to a new instance of your
> class.
> If not roll your own, you can create a function to copy all the property
> values to a new instance of the class.
>
> "Simon Verona" wrote:
>
>> Well, I could do that, but I was slightly oversimplifying the problem, I
>> actually change a number of properties, so I thought I could get away
>> with
>> saving the whole object rather than each property individually...
>>
>> Regards
>> Simon
>> "JohnFol" <OutlookExpr***@WibbleObbble.Com> wrote in message
>> news:SXw6e.17955$il.9389@newsfe5-win.ntli.net...
>> > ok, I created a new form called Form1 with a single button on it,. The
>> > code is as follows
>> >
>> > Dim MyCopyForm As New Form1
>> >
>> > MyCopyForm.BackColor = BackColor.Bisque
>> >
>> > MyCopyForm.Show()
>> >
>> >
>> >
>> > This gives me the copy I was after. I think the problem you are having
>> > is
>> > you explicitly set the "copy" to point to the original. Just try
>> >
>> > Dim backup as dmsreport
>> > backup.font=newfont
>> > backup.print
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > "Simon Verona" <n***@aphroditeuk.com> wrote in message
>> > news:OZdTPyqPFHA.2356@TK2MSFTNGP14.phx.gbl...
>> >> John
>> >>
>> >> I did try splitting the line into :
>> >>
>> >> dim backup as new dmsreport
>> >> backup=me
>> >>
>> >> but this seems to have the same affect.
>> >>
>> >> Regards
>> >> Simon
>> >> "JohnFol" <OutlookExpr***@WibbleObbble.Com> wrote in message
>> >> news:ahw6e.17857$il.15981@newsfe5-win.ntli.net...
>> >>> What happens if you use the New keyword?
>> >>>
>> >>>
>> >>> "Simon Verona" <n***@aphroditeuk.com> wrote in message
>> >>> news:eo1ASRqPFHA.2584@TK2MSFTNGP15.phx.gbl...
>> >>>>I have a custom class inherited from a third party control.
>> >>>>
>> >>>> Within the class, I need to make a backup copy of the class so that
>> >>>> I
>> >>>> can change the properties (font size etc) for printing.
>> >>>>
>> >>>> So, I'm using code such as...
>> >>>>
>> >>>>    Dim backup as dmsreport =me
>> >>>>    backup.font=newfont
>> >>>>    backup.print
>> >>>>    etc etc
>> >>>>
>> >>>>
>> >>>> I was expecting this not to change any of the parameters of my
>> >>>> original
>> >>>> object, however I find that "backup" is created simply as a
>> >>>> reference
>> >>>> to "me" and therefore "me" contains all the updates I subsequently
>> >>>> make
>> >>>> to the backup.
>> >>>>
>> >>>> How do I make a copy of the object so that I can work on the copy
>> >>>> without changing the original?
>> >>>>
>> >>>> Hope that this makes sense!
>> >>>>
>> >>>> Regards
>> >>>> Simon
>> >>>>
>> >>>
>> >>>
>> >>
>> >>
>> >
>> >
>>
>>
>>