Skip to main content

TcxFormatController Class

Manages the formatting of currency and date values for several controls.

Declaration

TcxFormatController = class(
    TcxMessageWindow,
    IInterface,
    IdxLocalizerListener
)

Remarks

This class provides the CurrencyFormat, RegExprDateEditMask, StandardDateEditMask, and StartOfWeek properties, which specify the currency and date formats for all editors registered within the TcxFormatController. Providing the same formatting for several editors is implemented via a ‘listener’ technique. An editor must implement the IcxFormatControllerListener interface and register itself within the TcxFormatController by calling its AddListener method. When the currency and date formats are changed, all listeners receive “format changed” notifications and thus their values are always formatted correctly. For instance, when the TcxCustomCurrencyEdit and TcxCustomDateEdit controls are created, they add themselves as listeners to the TcxFormatController global instance (cxFormatController). Every time currency and date formats are changed, the format controller calls the IcxFormatControllerListener.FormatChanged method for each listener to allow it to reflect the changes by updating specific properties, if necessary. When editors are destroyed, they call the RemoveListener method.

There are three ways to change currency and date formatting:

  • Update specific format settings exposed by the global FormatSettings variable in the SysUtils unit;

  • Change system locale settings;

  • Set the format controller properties mentioned above.

Default values for the date and currency formats are determined based on the system locale. Certain properties are constructed based on the ShortDateFormat, CurrencyString, CurrencyFormat, and other format fields exposed by the global FormatSettings variable. In RAD Studio 2010, these fields correspond to global variables defined in the SysUtils unit. You can programmatically change these fields/variables, however editors will not reflect changes until you manually call the format controller’s GetFormats and NotifyListeners methods.

If an application’s UpdateFormatSettings property is set to True, the TcxFormatController receives WM_WININICHANGE messages, recreates the currency and date format strings based on the system locale and SysUtils variables, and notifies its listeners of the format changes. Setting the format controller’s properties directly calls the NotifyListeners method. If several properties must be changed, use the controller’s BeginUpdate/EndUpdate mechanism to eliminate unnecessary repainting.

Inheritance

See Also