[REBOL] Mold and VID objects
From: sunandadh::aol::com at: 22-Dec-2001 7:32
Here's a well-known problem, and an attempt at a solution.
We all know it's bad luck to mistakenly print a VID object:
Layout [myButton: Button]
print mold Mybutton
will print scads of useless stuff, and may at times even hang your session.
The simple answer is don't do it.
But that doesn't work for me any more as I increasingly have data structures
that had Vid objects embedded within them, and I want to print those data
for example, my tree viewer uses the object:
TREE-OBJECT: make object! [
TYPE: copy "?" ; node type
SORTID: copy "" ; Sort order
ID: copy "?" ; external id for this item (may be duplicates)
NodeID: copy "" ; Internal use only. To give each node a unique
PARENTID: none ; Internal user only: internal id of parent
TITLE: copy "" ; Title to display
OPEN?: true ; Are child nodes displayed?
HIDDEN?: false ; Is this node displayed?
DATS: copy "" ; VID display attributes (Bold, Green, font-size
LEFTCLICK: copy "" ; VID Left click action
RIGHTCLICK: copy "" ; VID Right click action
VID-FACE: copy  ; VID face
Inner: copy  ; Child tree objects
The key point being that it contains a VID face, and I need to print it (and
all its child inners--also with VID faces) for debugging.
If you have similar problems, you might find the function below useful. I
call it uprint.r (for useful print). It recurses down objects and blocks,
skipping over VID faces. A VID face is empirically identified as being an
object with both OFFSET and PANE defined within it.
VID-ARRAY: copy  loop 50 [append VID-ARRAY mybutton] uprint "VID-ARRAY"
(Note the variable to print is in a string)
-- It's not fully error trapped (try uprint "system")
-- you can't start with a path (uprint "tree-object/open?" doesn't work)
-- it's not so good for printing functions (uprint "uprint")
But it solves a problem for me. And, if you find it useful, maybe you can
uPrint: func [Item [String!] /Inner Val Indent /local Item-Value Last-bit nn]
if none? indent [Indent: 0]
loop Indent [prin " "]
Last-bit: copy Item
error? try [Last-bit: last parse Item "/"]
[if error? try [Item-Value: get to-word Item]
[Print [Item " is not defined"]
switch/default form type? item-Value
[either error? try [Item-Value/offset Item-Value/Pane]
[Print [Last-bit ": make object!"]
foreach var next first Item-Value
[uPrint/Inner join Item ["/" Var]
get in Item-Value var Indent + 3]
[print [Last-bit ": VID Object (not printed)"]
[prin Last-bit prin [": ["]
for nn 1 length? Item-Value 1
[either any [object? Item-value/:nn Block? Item-value/:nn]
[uprint/Inner join Item ["/" nn]
indent + 3
[prin [mold Item-value/:nn " "]]
prin Last-bit print [":" mold Item-Value]