|
-
May 20th, 2004, 03:27 PM
#1
Thread Starter
Frenzied Member
Serialization
I have the following class file...
VB Code:
<Serializable()> Public Class GroupMember
Public Name As String
Public ID As String
Public Random As Double
End Class
<Serializable()> Public Class GroupMemberCollection
Inherits System.Collections.CollectionBase
Public GroupName As String
Public GroupStatus As String
Public Sub Add(ByVal Member As GroupMember)
' Invokes Add method of the List object to add a widget.
List.Add(Member)
End Sub
Public Sub Remove(ByVal index As Integer)
' Check to see if there is a GroupMember at the supplied index.
If index > Count - 1 Or index < 0 Then
' If no GroupMember exists, a messagebox is shown and the operation is
' cancelled.
System.Windows.Forms.MessageBox.Show("Index not valid!")
Else
' Invokes the RemoveAt method of the List object.
List.RemoveAt(index)
End If
End Sub
Public ReadOnly Property Members(ByVal index As Integer) As GroupMember
Get
' The appropriate item is retrieved from the List object and
' explicitly cast to the GroupMember type, then returned to the
' caller.
Return CType(List.Item(index), GroupMember)
End Get
End Property
End Class
I am using Serialization to save instances of this class (group files)... My problem is that when it serializes, it only saves the information for the last index of Members within the GroupMembersCollection...
So when I deserialize and try the following loop...
VB Code:
For i = 0 to GroupCollection.Count - 1
MsgBox(GroupCollection.Members(i).Name)
Next i
I get the last name in the collection over and over and over again.
Can someone help me here?
Thanks,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 20th, 2004, 09:43 PM
#2
It sounds like you are readding the same reference to a member. Post your code for adding members. You should be calling New on every member object otherwise you are just changing the same instance.
-
May 20th, 2004, 10:04 PM
#3
Thread Starter
Frenzied Member
I will have to do that tomorrow morning.
I think you may be correct, but I also think I checked for that...
If I am editing the same instance of the Member object, then why is it that it repeats the output (name or whatever) for the number of times equal to the number of members I should have added to the Group Collection? If I were editing the same instance, would it do this?
I believe the problem is when I serialize the Group Collection. Do I need to serialize each item in the collection seperately or should this be done when I serialize the whole collection?
Thanks in advance,
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
-
May 20th, 2004, 10:10 PM
#4
A collection doesn't need unique instances so it will let you keep adding in the same instance. So yes it would do that. And since you are using the index then it will show for each indexed entry in the collection.
If you serialize the collection it will serialize all items as well. NOTE: If you are using XML serialization then you have to mark the items part with a special attribute XMLArray or something like that for it to know its a collection of items.
-
May 21st, 2004, 08:54 AM
#5
Thread Starter
Frenzied Member
Nope. I'm using binary encryption... Some of the data is sensitive, so doing so will make the users a little happier... I thought of using XML for web publishing purposes later, but it's too much of a hastle.
Squirrelly1
Now happily married and still crankin' away at the keyboard.  Life is grand for a coder, no?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|