Including Bi-directional Functionality in Applications
Go Up to Enabling Application Code to Work for Different Locales
Some languages do not follow the left to right reading order commonly found in Western languages, but rather use the right to left reading order for words and the left to right reading order for numbers. These languages are termed bi-directional (BiDi) because of this separation. The most common bi-directional languages are Arabic and Hebrew, although other Middle East languages are also bi-directional.
The VCL supports bi-directional localization through the BiDiMode and ParentBiDiMode properties. TApplication has two properties, BiDiKeyboard and NonBiDiKeyboard, that allow you to specify the keyboard layout.
VCL objects that support BiDi
Standard | Additional | Win32 | Data Controls | Other classes |
---|---|---|---|---|
|
|
|
|
|
Note: THintWindow picks up the BiDiMode of the control that activated the hint.
Contents
BiDiMode property
The BiDiMode property controls the reading order for the text, the placement of the vertical scrollbar, and whether the alignment is changed. Controls that have a text property, such as Name, display the BiDiMode property on the Object Inspector.
The BiDiMode property belongs to the TBiDiMode enumerated type. TBiDiMode has four states: bdLeftToRight, bdRightToLeft, bdRightToLeftNoAlign, and bdRightToLeftReadingOnly:
State |
Description |
Sample |
---|---|---|
bdLeftToRight |
Draws text using left to right reading order. The alignment and scroll bars are not changed. For instance, when entering right to left text, such as Arabic or Hebrew, the cursor goes into push mode and the text is entered right to left. Latin text, such as English or French, is entered left to right. bdLeftToRight is the default value. |
|
bdRightToLeft |
Draws text using right to left reading order, the alignment is changed and the scroll bar is moved. Text is entered as normal for right-to-left languages such as Arabic or Hebrew. When the keyboard is changed to a Latin language, the cursor goes into push mode and the text is entered left to right. |
|
bdRightToLeftNoAlign |
Draws text using right to left reading order, the alignment is not changed, and the scroll bar is moved. |
|
bdRightToLeftReadingOnly |
Draws text using right to left reading order, and the alignment and scroll bars are not changed. |
ParentBiDiMode property
ParentBiDiMode is a Boolean property. When True
(the default) the control looks to its parent to determine what BiDiMode to use. If the control is a TForm object, the form uses the BiDiMode setting from Application. If all the ParentBiDiMode properties are True
, when you change Application's BiDiMode property, all forms and controls in the project are updated with the new setting.
FlipChildren method
The FlipChildren method allows you to flip the position of a container control's children. Container controls are controls that can contain other controls. Container controls are such as TForm, TPanel, and TGroupBox. FlipChildren has a single boolean parameter AllLevels. When AllLevels is False
, only the immediate children of the container control are flipped. When AllLevels is True
, children of all levels in the container control are flipped.
Delphi flips the controls by changing the Left property and the alignment of the control. If a control's left side is five pixels from the left edge of its parent control, after it is flipped the edit control's right side is five pixels from the right edge of the parent control. If the edit control is left aligned, calling FlipChildren will make the control right aligned.
To flip a control at design-time select Edit > Flip Children and select either All
or Selected
, depending on whether you want to flip all the controls, or just the children of the selected control. You can also flip controls in a container control by selecting the container control on the form, right-clicking, and selecting Flip Children from the context menu.
Note: Selecting an edit control and issuing a Flip Children > Selected command does nothing. This is because edit controls are not containers.
Other methods useful for Bi-directional functionality
There are several other methods useful for developing applications for bi-directional users.
VCL methods supporting BiDi:
Method | Description |
---|---|
Used with database controls. Checks to see if the alignment of a control can be changed. | |
A wrapper for database controls for checking alignment. | |
Changes the alignment parameter passed to it. No check is done for BiDiMode setting, it just converts left alignment into right alignment and vice versa. | |
Returns | |
Returns | |
Returns | |
Returns | |
Returns the correct draw text flags for the BiDiMode of the control. | |
Returns the | |
Adds the appropriate |