CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: copy a class

  1. #1
    Join Date
    Mar 2001
    Posts
    3

    copy a class

    If I have 2 declarations of class object
    DIM Cls as ADefinedClass
    DIM ClsOld as ADefinedClass

    SET Cls =new ADefinedClass
    CLS.ID ="ABC"
    SET ClsOld =Cls

    ' ------1 at this point ,ClsOld.id='ABC"
    CLS.ID="CCC"
    ' ------2 at this point ,ClsOld.id='CCC"


    Question:--
    How I programme the code if I want the ClsOld to have a copy of old cls ,one that its .ID will not changed whenever Cls Changed.
    It means that at point --2, I want the ClsOld.ID to remain as "ABC"


  2. #2

    Re: copy a class

    SET ClsOld =Cls -> now ClsOld e Cls are set to the same object. To make a copy of a class U must for example add a method in ADefinedClass.

    public function Clone() as ADefinedClass
    dim newc as ADefinedClass
    newc.id=me.id
    set Clone = newc
    end function

    DIM Cls as ADefinedClass
    DIM ClsOld as ADefinedClass

    SET Cls =new ADefinedClass
    CLS.ID ="ABC"
    SET ClsOld =Cls.clone

    ' ------1 at this point ,ClsOld.id='ABC"
    CLS.ID="CCC"
    ' ------2 at this point ,ClsOld.id='ABC"







Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured