PDA

View Full Version : cannot read window title


alkoor
07-14-2003, 02:46 PM
Say you have a window:

<window name="win1" title="Sample window"/>

I am trying to programmatically get/set this window's title:

canvas.win1.getAttribute('title')
//just returns empty string

canvas.win1.getTitle()
//returns error: no such method

canvas.win1.setAttribute('title', 'new title');
//doesn't do anything

canvas.win1.setTitle('New win title')
//this one works

So two questions:
1. why can't I work with title as with any other attribute ?
2. How come there's setTitle() but no getTitle() ? How can I read window title then ???

antun
07-14-2003, 03:10 PM
The problem here is with the window class. There are a number of defects in the Redmond components (of which <window> is one. We are redesigning all components, in clean modern LZX, from the ground up at the moment. Most of the Redmond components were written a very long time ago, and if you look at the code for them you'll see that they don't resemble LZX at all.

In short, we know they're in need of repair, and we're working on that.

Having said that, here's a way to get a getTitle() method:


<canvas debug="true">
<class name="mywin" extends="window">
<method name="getTitle">
return this.top.subviews[2].getText();
</method>
</class>

<mywin name="win1" title="Sample window">
<text>blah blah</text>
<button>Click here
<method event="onclick">
var tmp2 = canvas.win1.getTitle();
debug.write( 'tmp2: ' + tmp2 );

</method>
</button>
</mywin>
</canvas>


What I did was to make a new class called "mywin", and extend window. In that I added a method called getText().

Now you may be wondering how I got this bit:


return this.top.subviews[2].getText();


Check out this tip on reverse engineering with the debugger:

http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=59

Hope this helps,

Antun