Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!rutgers!brl-adm!seismo!mcnc!unc!rentsch From: rentsch@unc.UUCP Newsgroups: comp.lang.smalltalk Subject: Re: Smalltalk/V question Message-ID: <922@unc.unc.UUCP> Date: Sun, 15-Feb-87 01:27:32 EST Article-I.D.: unc.922 Posted: Sun Feb 15 01:27:32 1987 Date-Received: Tue, 17-Feb-87 05:50:40 EST References: <3060@gitpyr.gatech.EDU> Reply-To: rentsch@unc.UUCP (Tim Rentsch) Distribution: world Organization: CS Dept, U. of N. Carolina, Chapel Hill Lines: 76 In article <3060@gitpyr.gatech.EDU> krubin@gitpyr.UUCP (Kenny Rubin) writes: > QUESTION: how does one determine the names of instances that > have been created for a given class by application > of the 'new' method selector? > > PROBLEM: when I make a modification to a given class, i.e., > add/remove a new instance or class variable, I cannot > save the modification (from the ClassHierarchyBrowser). > Attempting to do so results in a window popping up that > says "Has Instances". The solution to the problem seems > to be to find all instances of the class (or subclass) > and set them equal to something other than an object of > the class I am trying to modify. Unfortunately, I can't > seem to be able to locate the names, and more so, who > is using them (containing the names). From the way you describe the problem I would guess that you are somewhat confused about the details of objects and how they are referenced (in particular about pointer semantics). Instances (i.e., objects) don't have "names", they just exist -- and the array you get back from 'allInstances' is indeed an array of instances, not an array of classes. So, let me proceed with solutions based on a guess as to what your actual situation is. I guess that you are either: (a) modifying system supplied classes, or (b) modifying classes that you yourself have written. I guess that you are doing (a) or (b), but not both. If you are modifying system supplied classes, try circumventing the problem by making subclasses of the classes you want to change, leaving the originals intact, and using the subclasses rather than the originals. This approach will only allow you to add instance variables, not remove them, but that's life. If you are modifying classes that you yourself have written, return to a system that does not have those classes added yet (so no instances exist), file the class definitions in, then add/remove variables as you see fit. The add/removes will cause recompilations but will work. (An alternative strategy is to manually edit the file containing the filed out definitons, adding/removing the variables in the file, and then filing in. Not a bad approach -- it's easy to figure out where to put those '!'s -- but be sure to keep a backup copy of the original file!) If you don't have a file out of your classes, the easiest thing might be to just type them in again (ugh!). [If anyone out there is using Smalltalk/V, is not filing out change sets, but wants to, reply by mail. Have I got a deal for you....] If you really are doing both (a) and (b), a combination of the two strategies may work. If neither of the proposed strategies is viable for you, and you are desparate enough to try a "flag day" approach, do the following: For each class C that you want to change Create C' that is just like C but with variables added/removed Execute smalltalk/V code "C allInstances do: [ :inst | inst become: (C' basicNew copyFromC: inst) ]" (You will have to have written 'copyFromC:' to do the right thing) Remove C from the system (C should now have no instances) Rename C' to C End for If the classes to be changed are all leaf classes (no subclasses) the above should work as written. If you need also to change non-leaf classes, changing C to C' means first changing S to S' for each subclass S of C. Hope this helps. cheers, Tim