PDA

View Full Version : Error while accessing class members declared views


tiziano.fagni
09-28-2005, 06:45 AM
Hi developers,
I need some help to fix some runtime errors that occcurs during the execution of this simple program:

<canvas>

<class name="test" extends="window" visible="false" closeable="true" resizable="true"
width="600" height="500" >



<attribute name="operation" type="string" value="view" setter="setOperation(operation)"/>



<method name="setOperation" args="op">

if (op == "view")
{
this.setAttribute("title", "Something1");

this.ViewTab.Tabs.TabGeneral.setAttribute("enabled", false);
this.ViewTab.Tabs.TabOther.setAttribute("enabled", false);

}
else if (op == "modify")
{
this.setAttribute("title", Something2");
}
else
{
this.setAttribute("title", "Something3");
}

</method>

<view name="ViewTab" y="10" width="${immediateparent.width}" height="${immediateparent.height}">

<tabs name="Tabs" width="${immediateparent.width}" height="${immediateparent.height}">
<tabpane name="TabGeneral" text="General info" width="${immediateparent.width}" height="${immediateparent.height}">
<simplelayout axis="y" spacing="20" />
<view width="${immediateparent.width}">
<simplelayout axis="x" spacing="20"/>
<text>Something1:</text>
<edittext ></edittext>
<text>Something2:</text>
<edittext multiline="true" height="50"></edittext>
</view>

</tabpane>
<tabpane name="TabOther" text="Other informations" width="${immediateparent.width}" height="${immediateparent.height}">

</tabpane>
</tabs>

</view>

</class>


<test visible="true" operation="view"/>

</canvas>




When i run the application in debug mode, the debugger give me these errors:

test.lzx:19:reference to undefined property 'ViewTab'
test.lzx:19:undefined object does not have a property 'Tabs'
test.lzx:19:reference to undefined property 'Tabs'
test.lzx:19:undefined object does not have a property 'TabGeneral'
test.lzx:19:reference to undefined property 'TabGeneral'
test.lzx:19:undefined object does not have a property 'setAttribute'
test.lzx:20:reference to undefined property 'ViewTab'
test.lzx:20:undefined object does not have a property 'Tabs'
test.lzx:20:reference to undefined property 'Tabs'
test.lzx:20:undefined object does not have a property 'TabOther'
test.lzx:20:reference to undefined property 'TabOther'
test.lzx:20:undefined object does not have a property 's


Have you any idea why I can't access the declared view inside the class from within the class itself (the method 'setOperation')?

Thanks for your help.
Cheers Tiziano

ballack
09-28-2005, 11:23 AM
Probably that ViewTab is not constructed yet.
You can try to set the attribute on initial load.


<test visible="true" oninit="this.setAttribute('operation', 'view');" />

tiziano.fagni
09-28-2005, 12:16 PM
Originally posted by ballack
Probably that ViewTab is not constructed yet.
You can try to set the attribute on initial load.


<test visible="true" oninit="this.setAttribute('operation', 'view');" />


Ok, you have reason, the example with your code works correctly. It seeems that the problem depend on the initialization phase because the construction of a tab component is quite expensive in term of time. So my question is this. Do you known if is there a general method to ensure that a tag declaration like my original one (<test visible="true" operation="view"/>) function in every occasion that is in a indipendent way relative to the amount of code that must be done in the construction of a new object? I ask this because I think the same problem occcurs also when you declare a new object programmatically. For example, in the following code I think you can encounter the same errors:

<method name="a_method">
var t = new test(canvas);
t.setAttribute('operation', 'view');
t.open();
</method>

How I can ensure that second line of code is executed after the object is instantied?

ballack
09-28-2005, 02:31 PM
I believe this would be helpful.

http://www.laszlosystems.com/lps-3.0/docs/guide/initialization-and-instantiation.html