[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Copying an object




Since the documentation for STRUCT_ASSIGN in 5.2.1 says
that both destination and source may be an object reference
when used inside an object method, the only "problem" is to make an
uninitialized instance of the object (like val = {STRUCT_NAME}).
But this could easily be implemented in an object's init method,
thus:

  FUNCTION BLAH::INIT,....,CLONE=CLONE
    
    IF OBJ_VALID(CLONE) THEN BEGIN
       IF NOT OBJ_CLASS(CLONE) EQ OBJ_CLASS(SELF) THEN ... ;ERROR
       STRUCT_ASSIGN,CLONE,SELF
       RETURN,1
    END
    :
    : ;;  Non-clone initialization code
  END

which would be called like this:

  clone = OBJ_NEW('BLAH',CLONE=ORIGINAL)

Of course, this doesn't deal with issues of "parents" or other
pointers to the cloned objects. But this will have to be dealt
with for each specific type of object.

Regards,

Stein Vidar