I have created a Collection object and Collection Item classes that works same as your requirements. Instead of using bare arrays, I have used Custom class and it's property to store collection of objects.
I created it so that you can build your own hierarchy by adding more child collections.
Here is the sample Code,
SET CLASSLIB TO objtest
LOCAL loMessageCollection AS Messages
LOCAL loMessage AS Message
LOCAL loAttachment AS Attachment
loMessageCollection = CREATEOBJECT("Messages")
loMessage = CREATEOBJECT("Message")
loMessage.Name = "Message1"
loAttachment = CREATEOBJECT("Attachment")
loAttachment.Name = "Attachment_1_of_Message_1"
loMessageCollection.Add(loMessage)
loMessageCollection.Items[1].Child.Add(loAttachment)
?loMessageCollection.Count
?loMessageCollection.Items[1].Children[1].Name
?loMessageCollection.Items[1].ChildCount
?loMessageCollection.Items[1].Index
loMessageCollection.Items[1].Children[1].Remove()
loMessageCollection.Items[1].Remove()
Send me an email and I will email you the code. Is there any other way of sending it via UT?
>I'm trying to create a wrapper object for a series of dll functions that allow me to do pop/smtp. I want to create a email object that contains an array of message objects. Each message object can contain an array of attachment objects. (Kind of like Outlook's object model. Folders object contains a Task object which contains an array of Item objects.)
>
>The problem I run into is this:
>
>My attachment object has a method called delete() so that I can delete an attachment like so:
>
>oEmail.oMessages[1].Attachments[2].delete()
>
>However, my Message object has a counter that tells me how many attachments I have. That counter needs to be updated if an attachment is deleted but the Message object has no way of knowing that the delete has taken place and that it's attachment counter needs to be updated.
>
>I could force a delete of an attachment through the Message:
>
>oEmail.oMessages[1].DeleteAttach(2)
>
>However, this is a little more inconvenient and I'd like to be able to delete the attachment via it's own method. Because the attachment object is housed in an array, there is no parent reference for it to be able to reference the Message and update the Message objects attachment counter.
>
>I thought of adding a Message pointer property to my Attachment class so that every attachment has a pointer to it's associated Message (kind of like implementing my own Parent) but something doesn't seem right about that. Wouldn't that create some kind of recursive reference and cause problems when trying to destroy an object?
>
>Thanks for whatever help you can offer.
- Jayesh