[comp.sys.mac.programmer] Problem with MacApp ".Clone"

d6caps@dtek.chalmers.se (02/27/90)

From: d6caps@dtek.chalmers.se
Newsgroups: comp.sys.mac.programmers
Subject: Problem with MacApp ".Clone"
Expires: 
References: 
Sender: 
Reply-To: d6caps@dtek.chalmers.se (Per Bergland)
Followup-To: 
Distribution: world
Organization: Chalmers Univ. of Technology, Gothenburg, Sweden
Keywords: MacApp 


I'm using MacApp 2.0b9.

Question :
   What's the meaning of making a method if you don't use it?

I intended to use the Tobject.Clone method and relied on Apple having
made multiple instances where necessary (i.e. where fields are objects
or handles).  It turned out this wasn't so. Why not?

Problem examples:

1)  Cloning a TView doesn't clone the subviews.

2)  is what made me discover this.  I cloned TCluster and got the
    same text in both after changing one. Freeing also gave some
    serious errors. It seemed the fDataHandle wasn't duplicated.


So, what?

Am I supposed to change all MacApp-classes and create the Clone method
myself? (Mucho work :-( )


Per Bergland  
d6caps@dtek.chalmers.se

anders@penguin (Anders Wallgren) (02/28/90)

In article <1990Feb26.185646.21302@mathrt0.math.chalmers.se>, d6caps@dtek writes:
>Problem examples:
>
>1)  Cloning a TView doesn't clone the subviews.
>
>2)  is what made me discover this.  I cloned TCluster and got the
>    same text in both after changing one. Freeing also gave some
>    serious errors. It seemed the fDataHandle wasn't duplicated.
>
>
>So, what?
>
>Am I supposed to change all MacApp-classes and create the Clone method
>myself? (Mucho work :-( )
>
>
>Per Bergland  
>d6caps@dtek.chalmers.se


While the behavior of ::Clone (or .Clone if you prefer...) may not
seem to be logical, at least it's documented:

MacApp 2.0 Globals, page 2:

"TObject.Clone:

"Purpose: To clone dependent objects referred to by the fields of an
object as well as cloning the object itself.  An object is dependent
on another object when the second object has the only (or the only
important) reference to the first object.  Dependency is a relatively
vague condition; when you override this method, you need to determine
what objects are dependent on SELF.

"The default version: Calls ShallowClone, and thus clones only the
object itself"

---

Thus, it's no wonder that you're getting the behavior you described -
Clone is just cloning the references to other objects, not the other
objects themselves - when you modify an object through a reference
field, you're also modifying it for all the clones.  You will probably
need to implement your own Clone method to Do The Right Thing.  This
seems silly, but it can be argued that this is the correct behavior,
given the description above.

anders

keith@Apple.COM (Keith Rollin) (03/05/90)

In article <1990Feb26.185646.21302@mathrt0.math.chalmers.se> d6caps@dtek.chalmers.se (Per Bergland) writes:
>
>I'm using MacApp 2.0b9.
>
>Question :
>   What's the meaning of making a method if you don't use it?
>
>I intended to use the Tobject.Clone method and relied on Apple having
>made multiple instances where necessary (i.e. where fields are objects
>or handles).  It turned out this wasn't so. Why not?
>
>Problem examples:
>
>1)  Cloning a TView doesn't clone the subviews.
>
>2)  is what made me discover this.  I cloned TCluster and got the
>    same text in both after changing one. Freeing also gave some
>    serious errors. It seemed the fDataHandle wasn't duplicated.
>
>
>So, what?
>
>Am I supposed to change all MacApp-classes and create the Clone method
>myself? (Mucho work :-( )
>
>
>Per Bergland  
>d6caps@dtek.chalmers.se


Per,

Anders Wallgren answered your concerns to some degree. I just wanted to mention that the MacApp team hasn't quite figured out just what cloning an object 
means. For instance, say you wanted to clone a TDialogView. Now, in a 
TDialogView, there are many references to other objects. There is fSuperView.  
Do you clone that? There is fSubViews, which is a TList. Do you clone that, or 
just copy it? How about all the objects contained in the TList. Do you clone 
them, or copy them? There is also the fNextHandler field. Clone, or copy? If 
you clone it, do you do a full clone, or a shallowclone? If you do a full 
clone, then you end up getting a duplicate copy of your entire event handler 
chaing. How about fTEView? Or fDocument? Or fPrintHandler?

You see, there's a big can of worms that has to be dealt with here. Even if the
MacApp team WERE to make a determination on what to do with those fields, it's
not given that those determinations would hold for all applications. Perhaps
someone would like to clone all the subviews, and yet another person would NOT
like them cloned.
-- 
------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc.  ---  Developer Technical Support
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions