On Jan 4, 2007, at 11:18 AM, Dave Crozier wrote:
> In that case is there a problem with the objects when they are
> simply placed
> onto a form.
>
> i.e if you create a panel in a form using
> panel=self.addObject(dabo.ui.dPanel)it isn't bound to the form
> itself by the
> name "panel" in any way unless you create it using self.panel.
It is bound, but not by the local 'panel' reference in your code.
Every Dabo control has a Name property. If you don't supply a value
for this when the object is created, it will be created using the
class name plus an incremental integer for uniqueness. Hence, if you
create 3 textboxes on a form, they will be given names 'dTextBox',
'dTextBox1', and 'dTextBox2'.
To see what I mean, take your code and add one more line:
panel = self.addObject(dabo.ui.dPanel)
print panel.Name
> Are you saying that panel=self.addObject(dabo.ui.dPanel) when
> created in a
> method should create the object so it can be referenced outside the
> method
> as self.panel (which is what I was assuming when testing)? If so, it
> doesn't.
No, what I'm saying is that you can reference it outside of the
method in which it was created as <formReference>.<panel.Name>
Let's say that if you run the code above, it prints 'dPanel' as the
value for panel.Name. Then from some other form method, you can
reference 'self.dPanel'.
As a slight digression under the hood, if you break down the code in
the statement:
panel = self.addObject(dabo.ui.dPanel)
what happens is that first self.addObject() is called with the class
to be created. In that method it instantiates the object from the
class definition, and in that process, the object is given a value
for its Name property. The method then returns a reference to the
newly-created object, and in the namespace of the calling method, the
name 'panel' is assigned to this returned reference. That's why when
the calling method exits, the local 'panel' reference is no longer
defined.
Here's something else to try:
panel = self.addObject(dabo.ui.dPanel, Name="razzamatazz")
print panel.Name
print self.razzamatazz.Name
In this example, we are setting the Name explicitly.
-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users