Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Save original object before make changes
Message
De
29/11/2012 12:10:05
 
 
À
29/11/2012 10:59:02
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01557223
Message ID:
01558377
Vues:
45
I think the problem is that you need to add the newly cloned object to your list, like this:
Public Shared Function payOff(ByVal origClientList As list(of Soma_Client)) As Decimal

Dim clientList As list(of Soma_Client) = New list(of Soma_Client)
dim ii as integer

for ii = 0 to origClientList.count-1
	clientList.Add(origClientList(ii).Clone)
loop
~~Bonnie




>I created a clone property in the client class which does what you say-creates a new instance, assigns values of current properties to new instance, and returns instance.
>
>This works in the simple case. For example, I create a new client instance
>from the existing values in origClient:
>
>
>Public Shared Function payOff(ByVal origClient As Soma_Client) As Decimal
>Dim Client As Soma_Client = New Soma_Client
>Client = origClient.Clone
>
>
>Very useful. However, if I try to use it in a "list of" case, I get an error.
>
>
>Public Shared Function payOff(ByVal origClientList As list(of Soma_Client)) As Decimal
>
>Dim clientList As list(of Soma_Client) = New list(of Soma_Client)
>dim ii as integer
>
>for ii = 0 to origClientList.count-1
>	clientList(ii) = origClientList(ii).Clone
>loop
>
>
>In this case I get an "index out of range" error.
>
>Hoping for magic, if I separate the two indexed expressions
>and use two statements:
>
>
>dim origClientRec as soma_client = new soma_client
>for ii = 0 to origClientList.count-1
>        origClientRec = origClientist(ii).clone
>	clientList(ii) = origClientRec.clone
>loop
>
>
>I still get "index out of range" error, but it occurs on the
>SECOND statement. If it means anything, the error display shows the little red line underneath the 'e' in clone in the second statement.
>
>I got the same results implementing the clone feature as a function in the client class.
>
>Perhaps I'm not defining my objects properly? Perhaps it can't be done? Thanks for your thoughts.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform