Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: layout within an object

From: brett::codeconscious::com at: 31-Jul-2001 21:27

Hi Mike,
> 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
> default.
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
== false
>> same? myview/name MyObject/name
== false
>> type? myview/page-layout
== object!
>> same? myview/page-layout MyObject/page-layout
== true 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 Nelson... 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): context-spec: [ name: "Edna Crabapple" page-layout: layout [ size 640x480 below h2 "Test" return button "Print Value" [print ["name in button action:" name]] ] ] MyObject: make object! context-spec myview: make object! context-spec myview/name: "Nelson Muntz" print myview/name view myview/page-layout view myobject/page-layout and see this:
>> same? myview/page-layout myobject/page-layout
== false HTH Brett.