Smalltalk, displaying OrderedCollection to List Widget
Hi I have an ordered collection of strings which I'm trying to display on a list widget. I do the following:
self displayWidget list: coll.
where displayWidget is a List Widget and coll is the OrderedCollection containing the strings. It will display it, but it displays it in a single line.
Instead of getting
line one
line two
line three
I get:
line oneline two开发者_开发知识库line three
I'm using visual works.*
Inside list:
you probably want something similar to
coll do: [:element | Transcript show element; cr]
When you send do: [:e | ...]
to a collection it evaluates the block once for each element in the collection, each time passing the element into element
.
Each time I'm sending cr
to Transcript
to add a carriage return after each element.
You can iterate the collection and send withCRs message to the Strings.
Here is an simple example:
| i |
i:= 0. [i < 5] whileTrue: [ Transcript show: 'Hello world.\' withCRs. i := i +1.
]
withCRs method replace each \ ocurrence for a new line and carry return.
Hope it helps you.
精彩评论