Defining Control Name Prefixes

You can define a prefix for a Control subclass (for example, a prefix of lbx_ for a ListBox control) so that when you add a control to a form in Painter, JADE inserts the appropriate prefix when prompting you for the name of the control.

To prefix a control, you must first define a controlNamePrefix method for the appropriate control subclass. You can add this method, which returns a string containing the appropriate prefix for that control, to the Control class or to any of its subclasses.

The following example shows a JADE method defined for the Button class in a user-defined schema.

controlNamePrefix(): String;
vars
begin
    return "btn_";
end;

The controlNamePrefix method is used only by the JADE Painter. No check for a control name prefix is made when you use the Class Browser or logic to add controls.

If you do not define a valid controlNamePrefix method for a control class, the JADE Painter uses the default control naming rules, which may be overridden.

If the control class has a caption property, the initial value for the caption is the control name (with a capitalized first letter and without the control name prefix applied) if you accept the default name when prompted to do so, or the actual text (with a capitalized first letter) that you specified as part of the name. For example, if the Painter detects you have changed the control name caption (for example, from Btn_Button1 to Btn_OK), the caption property is made equal to the caption name with the prefix removed so that the caption displays only the value that you specified (in this example, OK).

The name property for the control displays the full name (btn_OK in this example) in the Properties dialog.

The following image is an example of a form containing a group box that has no defined prefix and three buttons that have a defined prefix. This illustrates that only the non-prefixed portion of the control name is automatically selected so that you can change it to a caption of your choice, if required.

Now when you select your form in the Class List of the Class Browser, the controls listed in the Properties List display the prefixes that you defined for the controls in your schema.

The following image shows the controls specified for the MyForm form specified in the previous example.

The controlNamePrefix method can be defined once only for any class in a schema branch. You can therefore not override a prefix if the control is in a superschema and it has already implemented the controlNamePrefix method. In this case, set the superschema to the current schema and then change the method.

Control prefixes are not applied when you create a form using the Form Wizard, which prefixes all controls with ctl_. (The type of control is not known until the form is built after you have specified the name of the control.)