Re: [NTLK] NS Question: how to access slot in parent frame

From: Steve Weyer (weyer_at_kagi.com)
Date: Sun Mar 24 2002 - 15:33:53 EST


> Date: Sun, 24 Mar 2002 01:11:19 -0500
> From: Jim Witte <jswitte_at_bloomington.in.us>
>
> But I did find one quirk/bug/oddity: I have a base protoFloatNGo
> ("base") and a clParagraphView ("display") which is declared in the base
> view. The base view's viewSetupFormScript calls a method in "display"
> which then sets a slot in "base". Here's the code:
>
> base :=
> {viewSetupFormScript:
> func()
> begin
> display:updateDisplay();
> end,
> currentDisplayNum: nil,
> debug: "base",
> _proto: @180 /* protoFloatNGo */
> };
>
> display :=
> {updateDisplay:
> func()
> begin
> base.currentDisplayNum := 0;
> end,
> debug: "display",
> viewClass: 81 /* clParagraphView */
> };
> AddStepForm(base, display);
> StepDeclare(base, display, 'display);
>
> with the minutiae concerning viewBounds and whatnot removed. When I run
> it, it tells me that the variable 'base' is undefined in updateDisplay.
> Of course it is, it's not a variable.

I'd expect the variable base to be setup automatically by the protoFloatNGo,
since that's what the closebox uses to communicate to its parent (i.e., via
declareSelf: 'base).
perhaps this hasn't been setup before viewSetupformScript.

>Then I chage
> base.currentDisplayNum to parent.currentDispalyNum, and it tells me
> "Object {class: <an immediate>, funcPtr: 7037727, numArgs: 0} is
> read-only / evt.ex.fr;type.ref.frame / -48214" Anyone have any idea
> what's going on here?

as someone pointed out, you're somehow getting a reference to the
definition template, rather than the actual view object which causes a
readonly error. you could use :parent() to obtain the parent object, but
again during initial view creation, there could be a problem with all of the
objects and names not being quite setup yet.

another option would be to define a method in the parent to set the value,
e.g.,

in base:
setDisplayNum: func(num) currentDisplayNum := num,

in display:
updateDisplay: func() :setDisplayNum(0),

this should work, since it would find the method via parent inheritance,
and then when it set the variable, it would do it in context of the parent
view object -- which would avoid the read only error.

-- 
Steve

-- Read the List FAQ/Etiquette: http://www.newtontalk.net/faq.html Read the Newton FAQ: http://www.guns-media.com/mirrors/newton/faq/ This is the NewtonTalk mailing list - http://www.newtontalk.net



This archive was generated by hypermail 2.1.2 : Tue Apr 02 2002 - 14:03:30 EST