Largest Provider of Commercial Smalltalk
Cincom is one of the largest commercial providers of Smalltalk, with twice as many partners and customers than other commercial providers.

Tom Nies

Get Started

A Transcript Alternative 

Posted on in Categories ObjectStudio, VisualWorks

What if you want somewhere in which to write and review text other than the Transcript? Ideally we want somewhere that has the convenience of the Transcript but that’s much simpler than creating an application interface to write to.

There are likely numerous candidate techniques for this, including writing to a text file.  Here I will show how you can use the new Text2-based Document class (Text2.Document) to write text.

Where do you keep the document?

The first step is determining where you want to keep the document instance.  Transcript is globally known; if you want the same for your document, you could keep the instance in a global variable or a shared variable to the class(es) in which you want it to be available. Another place is as an instance variable.  For our example, let’s assume that we keep it in an instance variable named document.

Create the instance of document in the app’s initialize method or by sending a message to the app.

myApp document: Text2.Document new.

Note that there are other Document classes in the system, so it is usually necessary to specify that it is Text2’s document that you want.

Talking to your document

Now that you have your instance, the insert:  message is the primary way of adding a string to the document.

Now in your application: (for example)

document insert: ‘My  x value is: ‘ , x printString.

This works fine.  But for convenience, I want the api that’s used in the Transcript’s instance of TextCollector, so I can send messages like:


I added these methods to Document so that I can use the Transcript and easily switch to using an instance of Text2.Document.  I recommend keeping the added methods in a separate package.

OK, now you have written to the document; how do you see the results?

executing:    document inspect

will open it up.

Here are the methods I added to Text2.Document:

     self insert:  (String with: Character cr)

print: object
     self insert:  object printString.

show: object
     self insert:  object.

     self insert:  (String with: Character tab)