The Personal Money Tutorial

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

The Personal Money Tutorial

Bruce A. Peaslee
I'm working my way through the tutorial and so-far-so-good. One
question I have has to do with the method printOn: aStream.  I
understand it's purpose, but I don't know how to activate it. Is it
for the Transcript window? If so, how do I get it to print there?

Thanks!


Reply | Threaded
Open this post in threaded view
|

Re: The Personal Money Tutorial

Ian Bartholomew-4
Bruce,

> I'm working my way through the tutorial and so-far-so-good. One
> question I have has to do with the method printOn: aStream.  I
> understand it's purpose, but I don't know how to activate it. Is it
> for the Transcript window? If so, how do I get it to print there?

#printOn: is part of the Object protocol (i.e. applicable to every object in
the image) whose purpose is to add a readable description of the receiver to
the Stream passed as the argument.  So, for example, you can always be sure
that -

"create an object"
x := 'anyObject - inThisCaseAString'.

"create a stream to accept the description"
s := String writeStream.

"Use #printOn:"
x printOn: s.

"Inspect the resulting String"
s contents inspect

- will always work and answer a reasonable description of the receiver
object.  Look in the images for definitions of #printOn: to get some idea of
the different ways it can display it's receiver and note the Object class
has a default definition (which just uses the receiver classes name) that is
used when a class doesn't provide it's own implementation.

Transcript is a global variable containing the only instance of the
TranscriptShell class. Although this is not a subclass of Stream it does
have enough methods defined to make it behave as a Stream (#next, #nextPut:,
#cr etc). Because of this the following will also work -

x := 'anyObject - inThisCaseAString'.
x printOn: Transcript.
Transcript flush.  "Needed in D4 to make it visible"

There's a bit more to this (#printXXX v #displayXXX and the more "normal"
way of using Transcript) but you should come across explanations for these
in the tutorials/help files (or ask again here)

Ian