|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to back up an object...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 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 > 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 >> > > 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 >>> >> >> > > 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 >>>> >>> >>> >> >> > > 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 > >>>> > >>> > >>> > >> > >> > > > > > > > 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 >> >>>> >> >>> >> >>> >> >> >> >> >> > >> > >> >> >>
Dragging a mail from Outlook/Outlook Express in to a .NET VB app
DataGrid Bind to DataSet, then Bind to DaTaview, GOT ERROR...PLS HELP File pointer to be positioned at the last occurance of a keyword Lines and Boxes in VB.Net Newbie VB Question MDIChild form controls: how to pass information between them? Connectionstring Unexpected behaviour of MyClass (please ignore 1st post) Why use Dim outside of sub? Screen Resolution |
|||||||||||||||||||||||