Hidden Shadows

March 31, 2006

Over the last week I've run into this crazy problem in two separate applications, and it's directly related to Object Builder. More specifically, it's related to how I was using Object Builder. I realized that I was declaring some common elements in each object, such as the SQDataSet qry member that each active record object gets.

Even a first year computer science student can tell you why that's bad: common elements should be declared in the common ancestor class, so that if you even need to change how that item is handled it's fairly trivial. I decided to put the qry member into the ancestor class, initialize it with a database connection there and recompiled the app. Then my apps crashed with an inexplicable "Database Not Set" error.

The trick is that I didn't have the good sense to update my templates and regenerate my objects. The old Active Record objects all had a member called qry declared in the active record class. So when I was initializing the dborecord::qry member in the dborecord constructor, the dbo_author::qry member didn't get a connection to the database, since it's a separate object from the dborecord::qry. It's called a shadow parameter, and it's a classic mistake.
The proper solution is to redesign the templates so that there's no shadow parameter and regenerate the objects. It's easy to do, but also easy to forget. It all took about two hours to work out the first time, and another half hour to figure out the second time.

If you find yourself in a similar situation, take heart that you aren't alone, and check for shadows.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: