Accessing Morphs as objects

Richard A. O'Keefe ok at cs.otago.ac.nz
Mon Jun 10 01:55:54 UTC 2002


	> Here's a detailed example that works in Squeak 3.0.1.
	> 6. Now you can do things like
	>     star3516 heading: 10

	On the above example am I able to rename star3516 morph and use a more
	straightforward name for it?

That depends on what you mean by "rename".  For example, just now I
dragged a PolygonMorph onto a Workspace, and got
	polygon1118
I stuck "triangle := " in front of it, and "." after it, getting
	"triangle := polygon1118."
then executed the line (Cmd-D), and now I have the name "triangle" for
that morph.  To make it globally available,
	Smalltalk at: #<choose a name!> put: <the morph name that was dropped>

This doesn't change anything in the morph itself, of course.

	Is there a way for morphs saved in a file, upon reloading to associate
	them with global names?
	
You could always save a Dictionary of Morphs in an ImageSegment.


	> "inspect instances" I get an inspector on an array, with title
	> "The 297 instances of Morph".
	> So, from the browser you can *get to* instances, viewing instances using
	> inspectors and explorers, but you can't *browse* instances.

	Is there a way to search for instances - by name - in the browser (or
	somewhere) ?

Instances as such don't have names.  However, if you have an inspector on
a bunch of instances, you can always type
	self select: [:each | <whatever test you want>>]
in the bottom pane, select the line, and do InspectIt.

Morphs *do* have names, of a source.  Browse the method category
'naming' in class 'Morph'.  These names are of course part of the
data that go in a binary stream.

	Has Squeak such kind of introspection that I can list all
	instances of all objects, filter it by their class etc.?
	
Smalltalk allClassesDo: [:eachClass |
    eachClass allInstancesDo: [:eachInstance |
	...]]

Things like this get a little bit tricky when your code (...) creates new
instances, of course.  Check other methods in the same method categories
as those ones.

In my 3.0.1 Squeak on a 250MHz G3, with comparatively few changes to
the basic image except for deleting a lot of windows and flaps, count
to just count instances took 81.3 seconds and reported 229,692 objects.
So it's *possible*, but it isn't *cheap*.  You'd have to have a good
reason not to go straight to some particular class.




More information about the Squeak-dev mailing list