Including Bi-directional Functionality in Applications

From RAD Studio
Jump to: navigation, search

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
  • TButton
  • TCheckBox
  • TComboBox
  • TEdit
  • TGroupBox
  • TLabel
  • TListBox
  • TMainMenu
  • TMemo
  • TPanel
  • TPopupMenu
  • TRadioButton
  • TRadioGroup
  • TScrollBar
  • TActionMainMenuBar
  • TActionToolBar
  • TBitBtn
  • TCheckListBox
  • TColorBox
  • TDrawGrid
  • TLabeledEdit
  • TMaskEdit
  • TScrollBox
  • TSpeedButton
  • TStaticLabel
  • TStaticText
  • TStringGrid
  • TValueListEditor
  • TComboBoxEx
  • TDateTimePicker
  • THeaderControl
  • THotKey
  • TListView
  • TMonthCalendar
  • TPageControl
  • TRichEdit
  • TStatusBar
  • TTabControl
  • TTreeView
  • TDBCheckBox
  • TDBComboBox
  • TDBEdit
  • TDBGrid
  • TDBListBox
  • TDBLookupComboBox
  • TDBLookupListBox
  • TDBMemo
  • TDBRadioGroup
  • TDBRichEdit
  • TDBText
  • TApplication (has no ParentBiDiMode)
  • TBoundLabel
  • TControl (has no ParentBiDiMode)
  • TCustomHeaderControl (has no ParentBiDiMode)
  • TForm
  • TFrame
  • THeaderSection
  • THintWindow (has no ParentBiDiMode)
  • Menu
  • TStatusPanel

Note: THintWindow picks up the BiDiMode of the control that activated the hint.

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.

TListBox set to bdLeftToRight.jpg

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.

TListBox set to bdRightToLeft.jpg

bdRightToLeftNoAlign

Draws text using right to left reading order, the alignment is not changed, and the scroll bar is moved.

TListBox set to bdRightToLeftNoAlign.jpg

bdRightToLeftReadingOnly

Draws text using right to left reading order, and the alignment and scroll bars are not changed.

TListBox set to bdRightToLeftReadingOnly.jpg

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

OkToChangeFieldAlignment

Used with database controls. Checks to see if the alignment of a control can be changed.

DBUseRightToLeftAlignment

A wrapper for database controls for checking alignment.

ChangeBiDiModeAlignment

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.

IsRightToLeft

Returns True if any of the right to left options are selected. If it returns False the control is in left to right mode.

UseRightToLeftReading

Returns True if the control is using right to left reading.

UseRightToLeftAlignment

Returns True if the control is using right to left alignment. It can be overridden for customization.

UseRightToLeftScrollBar

Returns True if the control is using a left scroll bar.

DrawTextBiDiModeFlags

Returns the correct draw text flags for the BiDiMode of the control.

DrawTextBiDiModeFlagsReadingOnly

Returns the DT_RTLREADING flag or 0, depending on the value returned from the UseRightToLeftReading method.

AddBiDiModeExStyle

Adds the appropriate ExStyle flags to the control that is being created.

See Also