Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 1.3

COLUMN

Improving Object Communication

Issue: 1.3 (December/January 2002)
Author: Charles Yeomans
Author Bio: Charles Yeomans is a software developer in Lexington, Kentucky.
Article Description: No description available.
Article Length (in bytes): 5,474
Starting Page Number: 36
Article Number: 1318
Resource File(s):

Download Icon 1318.zip Updated: 2013-03-11 19:07:56

Related Link(s): None

Excerpt of article text...

Here's a problem recently posed on RB-NUG: you need to change the state of controls in a window depending on whether an edit field has text entered or not. Now, this is simple enough to do by adding code to the TextChange event handler of the edit field. But is this always the best way?

The purpose of event handlers is to allow you to modify the behavior of an object. Thus, for example, the TextChange event handler of an EditField allows you to modify the behavior of the EditField when its text has been changed. But telling the EditField to reach out and modify other objects can be bad behavior.

For simple projects, it's convenient, but as a window becomes complex, allowing controls to reach out to do things to other objects leads to code that is tangled and difficult to modify; changing an event handler of one control can generate a cascade of other changes.

Instead, consider a design in which objects that need to know when an EditField's text property changes can register with the EditField to be notified when this occurs. Upon notification, these controls can do as they wish.

Let's begin by defining a class interface, EditFieldTextChangedReceiver. This interface will have a single method, TextChanged(e as EditField). Objects that wish be notified when an EditField changes its text must implement this class interface.

...End of Excerpt. Please purchase the magazine to read the full article.