473,378 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Creating a new instance

ffa
Hi Guys

If I do something like:

Dim newClass As Customer
newClass = oCustomer (an existing Customer object)

Then when I make a change in oCustomer, the change is also applied to
newClass.

Is there some quick way to create a new instance of oCustomer that is an
independant object. I want to use this for some undo functionallity and
change logging.

Thanks
Jul 22 '07 #1
2 1192
I don't know if this is necessarily the quickest way. I usually implement
ICloneable, and in the Clone method, serialize the current object then
deserialize it to anothier instance to return from the method. This would
only be for fairly complicated classes though, as if there are only a few
properties, its not worth it.

"ff*@newsgroup.nospam" wrote:
Hi Guys

If I do something like:

Dim newClass As Customer
newClass = oCustomer (an existing Customer object)

Then when I make a change in oCustomer, the change is also applied to
newClass.

Is there some quick way to create a new instance of oCustomer that is an
independant object. I want to use this for some undo functionallity and
change logging.

Thanks
Jul 23 '07 #2
ff*@newsgroup.nospam wrote:
Hi Guys

If I do something like:

Dim newClass As Customer
newClass = oCustomer (an existing Customer object)

Then when I make a change in oCustomer, the change is also applied to
newClass.

Is there some quick way to create a new instance of oCustomer that is an
independant object. I want to use this for some undo functionallity and
change logging.

Thanks
There is no quick way to copy an object, as an object can be too
complicated for an automatic copy. It's up to the object itself to
implement cloning.

This can be done by implementing the IClonable interface, as
ModelBuilder suggested. Another common way of doing it is to make a
constructor that takes an object as parameter, so that you would do:

Dim newClass as New Customer(oCustomer)

The constructor would just copy the relevant data from the passed object
to make itself a copy of it.

--
Göran Andersson
_____
http://www.guffa.com
Jul 23 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jm | last post by:
I have a Form1 and two class files. In the first class, I call the second class. The second class references the Form1 notifyicon and changes the icon. It works. The problems is, however,...
15
by: Carlos Lozano | last post by:
Hi, What is the right way to create an OCX COM component. The component is already registerred, but can't create an instance. I am using the reference to the interop module created. If I use...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
3
by: Mag | last post by:
I am trying to install onDemand content manager for Linux I am looking at these instructions http://publib.boulder.ibm.com/infocenter/cmod/v8r3m0//topic/com.ibm.ondemand.mp.doc/ars1i07135.htm ...
1
by: vijju | last post by:
Hi all ! I'm an amateur to DB2.I installed DB2 ESE trial edition on my system.It was all going well and suddenly when i was trying to create an instance, i faced a problem which i listed it below....
7
by: Brett Romero | last post by:
I need a static version of a class that can be referenced anywhere as a singleton and the same class that can be used as instances. Can this be done without basically creating the same class twice...
26
by: nyathancha | last post by:
Hi, How Do I create an instance of a derived class from an instance of a base class, essentially wrapping up an existing base class with some additional functionality. The reason I need this is...
19
by: =?Utf-8?B?WWFua2VlIEltcGVyaWFsaXN0IERvZw==?= | last post by:
I'm doing my c# more and more like i used to code c++, meaning i'm casting more often than creating an instance of objects. like : protected void gvOrderDetailsRowDataBound(object sender,...
3
by: Peter Morris | last post by:
Hi all Let's say I am creating a model to represent classes and properties. In addition to this I need instances of classes and values for those properties. KEY: (AssociationEndName)
4
by: =?Utf-8?B?Z3JlZw==?= | last post by:
I am trying to create an instance of a 3rd party COM component, and I'm getting an error. I've opened a ticket with this vendor as well, but I want to approach it from the C# .NET side to make...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.