Consistent Naming Conventions for C++Builder Forms, Components and Events
Button7Click tells you that somebody clicked a button. It leaves you guessing about everything that matters. Does it save an invoice, cancel an edit, or close the application? Clear names remove that guessing. In a C++Builder project, they also connect the form designer to the code you read, debug, and maintain. A few shared rules can make that connection much easier to follow.
Name Each Identifier for Its Role, Then Apply Your Team’s Chosen Style Consistently.
- Separate form classes, component names, visible captions, and event handlers in your naming rules.
- Treat capitalization and component prefixes as team choices unless a language or framework requirement applies.
- Check proposed identifiers and make connected naming changes through the IDE.
Separate the Names That Describe a Form
A form has several names that serve different purposes. Confusing them creates unnecessary work. Consider an invoice editor with a class named TInvoiceEditForm, an instance named InvoiceEditForm, and a source file named InvoiceEdit.cpp. Its visible caption might simply be “Edit Invoice.” These names belong together, but they do not have to match character for character.
The class name describes a type. The instance name identifies a particular object. The filename helps developers locate its implementation. The caption speaks to the person using the application. Each name should make sense in its own setting.
The familiar T prefix fits the style of framework classes including TForm and TButton. Following that style for form classes makes a project feel familiar to C++Builder developers. It is a convention, however. C++ does not require every class name to begin with T.
Choose form names around responsibilities. TCustomerSearchForm is easier to place than TSearchForm when an application contains searches for customers, invoices, and stock. Avoid names tied to temporary screen positions. A form called TSecondForm loses its meaning as soon as the workflow changes.
Make Component Fields Read Like Descriptions
Default component names help you start a design. They rarely help you understand the finished feature. Edit1 identifies a control, but customerNameEdit identifies its purpose and its role in the interface.
Choose a component name before adding much code around it. For an invoice form, a coherent set might be invoiceNumberEdit, invoiceDatePicker, lineItemsGrid, and saveButton. A developer can understand those fields without opening the designer.
The component’s Name property and its visible text are separate concerns. A button can have saveButton as its name and “Save Invoice” as its caption. A later wording change should not automatically force a symbol rename. That separation also helps when captions are translated.
Avoid adding every available detail. invoiceCustomerNameSingleLineTextEdit is difficult to scan. If the form already provides the invoice context, customerNameEdit may be enough. Keep the words that distinguish the control from its neighbors.
Choose Prefixes or Suffixes Without Turning Preference Into Law
Some teams prefer btnSave and edtCustomerName. Others prefer saveButton and customerNameEdit. Both approaches can work. Prefixes group controls by kind in alphabetical views. Descriptive suffixes put the business meaning first.
The difficulty starts when a project uses both approaches without a reason. A reader should not have to guess whether the next save control is called btnSave, SaveBtn, or saveButton. Pick one pattern for new work and record a few real examples.
Keep abbreviations limited to terms the team understands. A familiar btn prefix can be readable in a project that uses it everywhere. A private invention like ivcCstNmEd makes readers decode the name before they can follow the code.
Component fields also deserve different treatment from business data. customerNameEdit refers to a control. customerName refers to a value. Preserving that distinction makes assignments and validation code easier to read.
Give Capitalization a Predictable Job
A workable team style uses PascalCase for form classes and camelCase for component fields, local variables, and helper methods. Under that policy, TInvoiceEditForm contains saveButton, while a helper named saveInvoice performs the operation. This is a sample policy, not a C++Builder requirement.
A project that already uses SaveButton and SaveInvoice can remain readable. Consistency within the existing code often helps more than changing every name to match a new developer’s preference. Agree on the scope of any style change before it spreads across unrelated files.
Decide how acronyms behave, too. customerIdEdit and customerIDEdit express the same idea, but mixing them makes spelling less predictable. Choose a rule for terms including ID, URL, and XML. Use examples in the style guide so contributors can copy the intended pattern.
Draft Names From Labels, Then Check Their Meaning
Plain-language labels can be useful starting points. “Customer email address” suggests customerEmailAddress. If that name belongs to an edit control, your component rule might turn it into customerEmailAddressEdit. Start with the meaning, then apply the category and capitalization rules.
A camel case converter can help draft camelCase names from those labels. Treat its output as a candidate. Developers still need to check that an identifier is valid, available in the relevant scope, and consistent with the surrounding code. Rename existing symbols through the IDE rather than replacing text with an unchecked result.
Visible labels do not always make good identifiers. “Continue” could mean saving a draft, opening payment details, or submitting an order. A name should describe the stable responsibility behind the wording. submitOrderButton may remain useful even if its caption later becomes “Place Order.”
For ordinary application identifiers, familiar letters and digits keep typing and searching straightforward. Start with a letter, avoid spaces and punctuation, and check for C++ keywords. Avoid reserved identifier patterns, including double underscores and an underscore followed by an uppercase letter.
Keep Event Properties Separate From Handler Methods
OnClick is an event property. saveButtonClick is a method assigned to handle that event. They are related, but they are different identifiers. The On prefix belongs to many framework event names. It does not mean every method that handles an event must begin with On.
The Object Inspector provides the connection between an event and its handler. Double-clicking an event entry can generate the handler declaration and implementation structure. Existing compatible handlers can also be assigned through the Events tab. The method’s signature must match the event type; its spelling alone does not establish the connection.
A common IDE naming pattern combines the component name with the event name, producing a method resembling Button1Click. Naming the component first gives that generated method a better starting point. With a button named saveButton, saveButtonClick is easy to trace back to the designer.
Here is a compact VCL example using that team style:
void __fastcall TInvoiceEditForm::saveButtonClick(TObject *Sender)
{
saveInvoice();
}
The event handler describes the interface interaction. The helper describes the operation. Keeping those responsibilities separate lets another entry point call saveInvoice without pretending that a button was clicked.
Name Shared Handlers for Their Shared Responsibility
A handler named after one control becomes misleading when several controls use it. Suppose a toolbar button and a menu item both export the current report. A shared name like exportReportExecute can describe their common operation more clearly than exportButtonClick.
Actions are useful when a command appears in several places. If your form uses a TAction named exportReportAction, a handler named exportReportActionExecute keeps the relationship visible. The action can provide a shared command for multiple interface elements.
Use names that match the actual shared behavior. handleClick tells the reader very little. filterChanged gives a clearer reason for several filter controls to share a handler. If the method contains unrelated branches for unrelated controls, reconsider whether those events belong together.
Rename Through the IDE and Verify the Connections
Renaming a designer-managed component involves more than changing a word in a C++ file. The form resource, class declaration, implementation, and event assignments can all matter. Use the Object Inspector for component names and event assignments. Use an applicable IDE rename refactoring for code symbols.
Support can vary with the symbol and IDE version. Preview changes when that option is available. After a rename, inspect the declaration and implementation, reopen the form, and check the relevant event entries. Do not assume that every related name has changed merely because one edit succeeded.
Search for the old spelling to find references that symbol-aware tools may miss. These can include comments, string-based lookups, configuration entries, or tests. Review each match in context instead of applying a project-wide replacement.
Build the project and exercise the affected interaction. For a renamed save button and handler, open the form, edit an invoice, and save it. Compilation checks the code, while the interaction checks that the expected event still reaches the expected behavior.
Write a Small Naming Agreement People Can Use
A useful naming guide should fit beside everyday development. State the form class pattern, component pattern, handler pattern, and acronym rule. Include actual project examples. A paragraph showing TCustomerSearchForm, customerNameEdit, and customerNameEditChange is easier to apply than a broad instruction to “use meaningful names.”
Explain any deliberate differences between designer-managed code and handwritten helpers. A team may preserve established PascalCase handlers while using camelCase for new internal methods. That choice can work if its boundary is clear. Unexplained variation creates friction.
For older projects, improve names as part of focused maintenance. Rename controls in the form you are already changing, verify their connections, and keep unrelated renames separate. Smaller changes make review easier and reduce the chance of overlooking a broken reference.
Let the Next Reader Follow the Form
Good names let someone move from a visible control to its component field, then to its event handler and underlying operation. saveButton, saveButtonClick, and saveInvoice tell that story with little explanation.
Choose conventions that suit the project, distinguish them from framework requirements, and apply them with care. The payoff arrives during ordinary work: finding a control, reviewing a change, or fixing a bug without spending the first ten minutes translating names.