[REBOL] Re: layout within an object
From: brett::codeconscious::com at: 31-Jul-2001 21:27
> However, in the script at the end of this email, an instance variable
(name) gets set after the object is
> created, and if you "print myview/name" you get the value you'd expect,
i.e., Nelson Muntz.
Actually you are creating two objects - one referred to as "MyObject" and
another referred to as "myview".
> But once the view is displayed, if you click the Print button, it will
print the original value of the variable,
> Edna Crabapple. It seems like the block for the Print button action is
being evaluated when it's created
> and then not evaluated again when it's actually clicked.
> I figured out that if I wrap the layout definition inside of a block
[layout [size 640x480 ....] then I can use
> "view do [myview/page-layout]" and get the correct results, which I
believe further supports my theory that
> the action is being evaluated once at the start. According to the
developer's guide, you can wrap things in
> a layout with a do [...] to cause them to be evaluated once at creation
time. But this really seems to be the
It certainly appears that way - but there is an alternative. Both of your
objects share the same page-layout object which ultimately (deeper down)
contains the button action - in reality a Rebol function. Thus both objects
share the same functionality.
So you have two objects. They have different "name" fields but share the
exact same page-layout
>> same? myview MyObject
>> same? myview/name MyObject/name
>> type? myview/page-layout
>> same? myview/page-layout MyObject/page-layout
So when you set the name to "Nelson Muntz" you are affecting the myview
field name but nothing refers to it.
For kicks, try your code again but instead of setting myview/name to
set Myobject/name instead like this:
myobject/name: "Nelson Muntz"
Bye bye Edna...
So you see that the function works, but it is looking at a "name" different
to what you were expecting.
The short answer, which I'm not entirely sure if I'll get away with is, you
don't need to make myview just use MyObject :)
Now before you ask, because I don't think I'll get away with the short
answer, how you can have two windows share the same layout but act on their
own data try this (only one of multiple ways):
name: "Edna Crabapple"
page-layout: layout [
button "Print Value" [print ["name in button action:" name]]
MyObject: make object! context-spec
myview: make object! context-spec
myview/name: "Nelson Muntz"
and see this:
>> same? myview/page-layout myobject/page-layout