Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!iuvax!maytag!watstat!dmurdoch From: dmurdoch@watstat.uwaterloo.ca (Duncan Murdoch) Newsgroups: comp.lang.pascal Subject: Re: (one way to) Copying objects in Turbo Pascal 5.5 Message-ID: <1990May25.132722.29073@maytag.waterloo.edu> Date: 25 May 90 13:27:22 GMT References: <4878@plains.UUCP> Sender: daemon@maytag.waterloo.edu (Admin) Organization: University of Waterloo Lines: 35 In article <4878@plains.UUCP> gus@plains.UUCP (jim gustafson) writes: >>I'd like to have a constructor for an object that just copies another instance >>of it or one of its descendants, and (the hard part) also copies the type >>information. > >Here's one way to get part of what you want. Thanks for your reply. Your program works fine, but isn't quite what I wanted. Here's some more background: maybe I'm just approaching the problem the wrong way entirely. I'm trying to write some objects for representing statistical datasets. The simple model I have in mind is that a dataset is a one dimensional array of pointers to cases, and cases can be just about anything, but they're all descended from an object that contains a pointer to some data, and a method to return the size of the data. (Since they're descendants, they may contain lots of other stuff too.) I've got a dataset constructor called copy that can duplicate a dataset by making copies of all the pointers to cases. I'm trying to add a method for making copies of the cases as well, in case I do some kind of destructive manipulation of them, and don't want to lose the originals. The problem is that this is a dataset method, and the dataset object only knows about the base case object. I guess I can give each case type a virtual method that knows how to make a duplicate of itself, but I'd like to avoid the work: if I can write a method once for the base that can perform the duplication on any descendant that sticks to the basic form described above, it'll be that much easier to use. By the way, since yesterday I've pored through the OOPS manual and think I can do what I want by writing the constructor in assembler. I'd rather avoid that, so I'm still hoping for alternative suggestions. Duncan Murdoch