On Mar 17, 2007, at 2:09 AM, johnf wrote:

> Good questions!  I'll provide an example:
> I sub-class a dialog (MyDialog).  I do this because I need a modal  
> form.  I
> add several objects (textboxes, grid,buttons).
> As you are aware notifyUser() is not a method of dialog.  Who would  
> have
> expected that a dialog would need notifyUser.   But I need a way to  
> notify
> the user of some action.  I could recreate some sort of dialog  
> within my code
> but then I have a calling "dForm" that has notifyUser.  But how do  
> I make a
> reference to the calling "dForm"?  I could say
> callingForm = self.Parent.  But what happens if later I move  
> "MyDialog"  in
> the call stack?  Maybe if I had passed a reference to MyDialog like  
> "self" I
> wouldn't worry.

        A good programming rule-of-thumb is to treat controls as dumb  
objects, and limit what they "know". In this case, the textbox should  
only "know" self, self.Parent, self.Form, and self.Application.

        If you have a case where some action in a textbox on one form needs  
to trigger an action on some other form, *you* may know this, but the  
textbox shouldn't. All it should do is self.Form.doSomething(). The  
textbox's form should have a reference to the other form, and it is  
up to the form to handle that message from the textbox; in this case,  
to pass it on to the other form.

        This may seem like extra work, but it keeps the relationships among  
objects much cleaner, and decouples the controls of one form from  
other forms.

-- Ed Leafe
-- http://leafe.com
-- http://dabodev.com



_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users

Reply via email to