Back to Devexpress

cxFormatController Method

vcl-cxformats-54e24f36.md

latest4.0 KB
Original Source

cxFormatController Method

Provides access to the global editor format controller.

Declaration

delphi
function cxFormatController: TcxFormatController;

Returns

TypeDescription
TcxFormatController

The global format controller.

|

Remarks

Call the cxFormatController function to access the global format controller that allows you to configure currency and date formats for all supported editors in the application project (TcxCustomCurrencyEdit and TcxCustomDateEdit descendant instances).

Available Options

Use the global format controller together with the FormatSettings global variable declared in the standard System.SysUtils unit to configure currency, date, and time formatting settings for all supported DevExpress editors in the application.

Use cxFormatController.StandardDateEditMask and cxFormatController.StandardDateTimeEditMask properties to define date and time input masks. Call the GetFormats procedure to generate date and currency formats based on current locale settings and options accessible through the FormatSettings global variable.

Refer to the TcxFormatController class description for detailed information on all available options.

Code Example: Customize Global Format Settings

The following code example changes multiple date format settings for all date editors in the application:

delphi
uses
  System.SysUtils, // Declares the global FormatSettings variable
  cxFormats, // Declares the global cxFormatController function
  cxDateUtils; // Declares date-related types

  // Define VCL format settings
  FormatSettings.DateSeparator := '-'; // Defines the date separator
  FormatSettings.ShortDateFormat := 'yyyy-MM-dd'; // Defines the short date format
  // Configure the format controller
  cxFormatController.BeginUpdate; // Initiates the following batch format controller change
  try
    cxFormatController.UseDelphiDateTimeFormats := True; // Applies the defined VCL format settings
    cxFormatController.StartOfWeek := dMonday;
    cxFormatController.FirstWeekOfYear := fwyFirstFullWeek;
    cxFormatController.GetFormats; // Generates the required date and currency formats
  finally
    cxFormatController.EndUpdate; // Calls EndUpdate regardless of the batch operation's success
  end;
cpp
#include "System.SysUtils.hpp" // Declares the global FormatSettings variable
#include "cxFormats.hpp" // Declares the global cxFormatController function
#include "cxDateUtils.hpp" // Declares date-related types

  // Define VCL format settings
  FormatSettings.DateSeparator = "-"; // Defines the date separator
  FormatSettings.ShortDateFormat = "yyyy-MM-dd"; // Defines the short date format
  // Configure the format controller
  cxFormatController()->BeginUpdate(); // Initiates the following batch format controller change
  try
  {
    cxFormatController()->UseDelphiDateTimeFormats = true; // Applies defined VCL format settings
    cxFormatController()->StartOfWeek = dMonday;
    cxFormatController()->FirstWeekOfYear = fwyFirstFullWeek;
    cxFormatController()->GetFormats(); // Generates required date and currency formats
  }
  __finally
  {
    cxFormatController()->EndUpdate(); // Calls EndUpdate regardless of the batch operation's success
  }

See Also

cxFormats Unit