Delphi Clinic C++Builder Gate Training & Consultancy Delphi Notes Weblog Dr.Bob's Webshop
Bob Swart (aka Dr.Bob) - Medical Officer Kylix Developer's Guide
 Dr.Bob's Tip-Of-The-Hat #9
See Also: Delphi Papers, Columns and other Tip-Of-The-Hats

Components and Names
The past three tips have introduced three nice components: a right-aligned editbox (TB42Edit), a shadowing label (TB42Label) and a data-aware edition of the right-aligned editbox (TB42DBEdit). Originally, their names were T42Edit, T42Label and T42DBEdit (without the "B" before the "42"). There's a good reason why I renamed them, because there's something special about the component names (Yes, it has to do with the "42" in the name).
If you install the T42Edit, T42Label and T42DBEdit components (for example inside the dclusr.bpl package), then you get no error message or problem. And after installation, you see these three new components appear on the component palette (in the DrBob42 tab in my case).
However, if you try to drop a T42Edit component on a form, you get an error message (an exception actually) telling you that 42Edit1 is not a correct component name:

This is caused by the fact that each component that you drop on a form will automatically get a name for itself. And this name is based on the type of the component, minus the "T"-prefix, with a number appended to it (the first number that's still free, starting with 1).
In the case of a TButton, that would be Button1. In the case of T42Edit, that would be... 42Edit1 indeed, and that's not a valid identifier, since it starts with a 42 instead of a letter.

I want to emphasize that although the names are generated by Delphi, I do not consider it a bug, but merely a feature, and the fact that it causes problems with my suggested component names (T42Edit, T42Label and T42DBEdit) is caused by myself, and easily fixed (for example by using another prefix, like "B42" or "DrBob42").

This webpage © 2001-2009 by Bob Swart (aka Dr.Bob - All Rights Reserved.