Results 1 to 6 of 6

Thread: Copying an object

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 1999
    Location
    London, UK
    Posts
    4

    Question

    Hi,

    I have a very simple question. How do you copy an object? And I'm not talking about creating another reference to an object, I'm talking about creating another copy of an object.

    Please help...


    Thanx in advance, Steve.

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    memcopy API ??

    create a new object reference but don't set it. then use memcopy from the other object.

    Don't ask me for code as I've never had to do it before
    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  3. #3
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    For some reason you can't, I think it's beacuse of the way the interface and data are combined very closely, I usually incluse a function inside all my class modules that creates a copy of it, but other than that there's not a lot you can do, You could try something with the copymemory API but I don't think it'll work.

  4. #4
    PowerPoster Fox's Avatar
    Join Date
    Jan 2000
    Location
    *afk*
    Posts
    2,088
    I think memcpy should work... you just have to know the size of your object, as I remember you can get it using LenB(Var)...

  5. #5
    Frenzied Member
    Join Date
    Mar 2000
    Posts
    1,089
    LenB doesn't work for objects. Also the object variable is an interface to the object, the data is stored elsewhere, I'm prety sure you'll just create another reference.Try anyway.

  6. #6
    Addicted Member
    Join Date
    Jan 2000
    Location
    Oshkosh, WI
    Posts
    163
    I tend to agree with Sam the only way I've been able to make a copy of an object it create a function that copies each property value to the new object. It's a brute force method but it works.

    If anyone has a neater solution I would be all for it.
    Glenn D
    Development/Analyst

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