Go to Advanced Groups Search Preferences Groups
Google Help
Groups
Home [IMG] [IMG] ________________________________ [ Google Search ]
Groups [IMG]
Groups search result 9 for clone method vb
Search Result 9
From: Larry Serflaten (
[email protected])
Subject: Re: Copying data from one collection to another alters TWO
different collections?
View: Complete Thread (11 articles)
Original Format
Newsgroups: microsoft.public.vb.general.discussion
Date: 2002-10-18 14:50:04 PST
"VB Guy" <
[email protected]> wrote
> I've built the Clone functions... This definately impact performance, but it
> works. You'll notice the loop to clone each activity object. Just wondering
> if there is an easy way to copy a collection.
You are using objects, within objects. This is precisely why the Collection object
cannot provide a Clone method for you, it would not know how many levels deep
you need to go.
To help performance you can reduced the number of calls on your objects.
You can do that by providing a means to create an object from passed parameters.
This would not help your Agent, but it could be used on your Activities class that
has no embedded objects, or, has only primative types for properties.
A method I've used more than once is to give the object a Copy property that
transfers all the properties to and from a string. Great for saving to a file, and
in this instance to make an exact copy.
http://groups.google.com/groups?selm=38776056.1435%40usinternet.com&oe=UTF-8
(A more detailed example from my VB4 days, using GetSerial and SetSerial
routines instead of one Copy property)
http://groups.google.com/groups?selm=3668AEA1.2F2C%40mail.usinternet.com&oe=UTF-8
Your Agent.Clone might then look like:
Public Function Clone() As clsAgent
'Return a cloned copy of the agent
Dim xActivity As clsActivity
Dim xClone As clsActivity
Set Clone = New clsAgent
Clone.Name = Me.Name
For Each xActivity In Me.cActivities
Set xClone = New clsActivitiy
xClone.Copy = xActivity.Copy
Clone.cActivities.Add xActivity.Clone
Next xActivity
Set xClone = Nothing
Set xActivity = Nothing
End Function
You might then add a special function to your Agent to accept the
Activity.Copy, and from that add a new activity to the Agent.
'clsAgent
Friend Sub AddActivityCopy(ByRef Data as String)
Dim xAct as clsActivity
Set xAct = new clsActivity
xAct.Copy = Data
cActivities.Add xAct
Set xAct = Nothing
End Sub
Then your Agent.Clone method looks like:
Public Function Clone() As clsAgent
'Return a cloned copy of the agent
Dim xActivity As clsActivity
Set Clone = New clsAgent
Clone.Name = Me.Name
For Each xActivity In Me.cActivities
Clone.AddActivityCopy xActivity.Copy
Next xActivity
Set xActivity = Nothing
End Function
This is all done to reduce the amount of code necessary to get the job
done. If you execute less code, obviously, it is going to run faster....
Have fun!
LFS
----------------------------------------------------------------------
Google Home - Advertise with Us - Business Solutions - Services & Tools -
Jobs, Press, & Help
(c)2003 Google