How to back up an object...

  • Thread starter Thread starter Simon Verona
  • Start date Start date
S

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
 
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
 
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
 
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
 
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.
 
Thanks, I'll have to do that.

Regards
Simon
Dennis said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top