DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Jacob Grass Guest

    Deriving from Treenode

    I have class that I derived from treenode. I simply added a couple of
    properties to it. For some reason, the Clone method is crapping out on me.
    I am assuming that I need to override the clone method and provide my own
    implementation for my own class. Unfortunately, I really have no idea how
    to do this. . . All of my attempts have resulted in the references coming
    across to the new object. Furthermore, in my custom implementation, will I
    have to recursively clone all child nodes?

    Any insights on this issue would be much appreciated. Thank you.

    Jacob



  2. #2
    Bill McCarthy Guest

    Re: Deriving from Treenode

    Hi Jacob,

    I think you will have to. Something along the lines:

    <pseudo code not tested>

    Public Function Clone() as TreeNodePlus ' or as object

    Dim tn as New TreeNodePlus
    With tn
    .Text = Me.Text
    .......
    End With

    Dim tnChild as TreeNodePlus
    For each tnChild in Me.Nodes
    tn.Nodes.Add(tnChild.Clone())
    Next

    return tn

    End Function


    "Jacob Grass" <JGrass@AbilitiSolutions.com> wrote in message
    news:3b55f568$1@news.devx.com...
    > I have class that I derived from treenode. I simply added a couple of
    > properties to it. For some reason, the Clone method is crapping out on

    me.
    > I am assuming that I need to override the clone method and provide my own
    > implementation for my own class. Unfortunately, I really have no idea how
    > to do this. . . All of my attempts have resulted in the references coming
    > across to the new object. Furthermore, in my custom implementation, will

    I
    > have to recursively clone all child nodes?
    >
    > Any insights on this issue would be much appreciated. Thank you.
    >
    > Jacob
    >
    >




  3. #3
    Jacob Grass Guest

    Re: Deriving from Treenode

    Bill-

    Yup. . .That's the consensus I have been getting. The Treenode.Clone method
    is very broken for this type of implementation, so, I ended up doing
    something similar to what you have suggested below. . .

    Thanks.

    Jacob

    "Bill McCarthy" <bill_mcc@iprimus.com.au> wrote in message
    news:3b57cd86@news.devx.com...
    > Hi Jacob,
    >
    > I think you will have to. Something along the lines:
    >
    > <pseudo code not tested>
    >
    > Public Function Clone() as TreeNodePlus ' or as object
    >
    > Dim tn as New TreeNodePlus
    > With tn
    > .Text = Me.Text
    > .......
    > End With
    >
    > Dim tnChild as TreeNodePlus
    > For each tnChild in Me.Nodes
    > tn.Nodes.Add(tnChild.Clone())
    > Next
    >
    > return tn
    >
    > End Function
    >
    >
    > "Jacob Grass" <JGrass@AbilitiSolutions.com> wrote in message
    > news:3b55f568$1@news.devx.com...
    > > I have class that I derived from treenode. I simply added a couple of
    > > properties to it. For some reason, the Clone method is crapping out on

    > me.
    > > I am assuming that I need to override the clone method and provide my

    own
    > > implementation for my own class. Unfortunately, I really have no idea

    how
    > > to do this. . . All of my attempts have resulted in the references

    coming
    > > across to the new object. Furthermore, in my custom implementation,

    will
    > I
    > > have to recursively clone all child nodes?
    > >
    > > Any insights on this issue would be much appreciated. Thank you.
    > >
    > > Jacob
    > >
    > >

    >
    >




Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links