Skip to main content

TcxButtonEdit Class

An unbound single-line text editor with embedded buttons.

Declaration

TcxButtonEdit = class(
    TcxCustomButtonEdit
)

Remarks

A button editor is a single-line text editor with one or more embedded buttons and support for masked input.

VCL Editors Library: A Single-Line Text Editor with Embedded Buttons

Button Collection

A button editor maintains a collection of embedded buttons accessible through the Properties.Buttons property.

To associate editor buttons with specific functionality in your application, you can associate each button with an action object (a TBasicAction descendant instance) or handle the Properties.OnButtonClick event as demonstrated in the code example below.

Main API Members

The list below outlines key members of the TcxButtonEdit class. These members allow you to configure button editors.

Appearance Settings

Style | StyleDisabled | StyleFocused | StyleHot | StyleReadOnly

Allow you to define individual appearance settings for different editor states.

Tip

To apply the same style settings to multiple editors, use a TcxEditStyleController component. If you need to apply the same style settings to all editors in your application, you can use a TcxDefaultEditStyleController component.

Styles
Provides access to individual styles applied to the editor in different states.
Transparent
Specifies if the editor is transparent in GDI render mode.
Clear
Clears the editor.
CopyToClipboard | CutToClipboard | PasteFromClipboard
Allow you to perform clipboard operations.
EditValue
Specifies the edit value.
OnEditing
Allows you to prevent users from activating the editor.
ResetEditValue
Restores the previous edit value before the pending change is applied.
SelectAll
Selects editor content.
ValidateEdit
Validates the display value.

Editor Settings and Repository Items

ActiveProperties
Provides access to the current editor settings regardless of their source. This property set does not allow you to customize editor settings.
GetPropertiesClass
Returns the actual editor settings type.
Properties
Allows you to customize editor settings directly if the editor does not have an assigned repository item.
RepositoryItem
Specifies a repository item as an external source of editor settings. A repository item has priority over other editor settings.

General-Purpose API Members

AutoSize
Specifies if the editor automatically adjusts its size to fit content.
Enabled
Specifies if the editor is enabled.
CanModify
Identifies if the editor is in read-only mode.
IsEditValidating | IsHiding | IsPosting
Allow you to identify the current operation in the editor.
ShowHint
Specifies if the standalone editor can display hints. To enable hints for an in-place editor in a container control, set its OptionsBehavior.CellHints[1] property to True.
SupportsSpelling
Identifies if the editor supports the TdxSpellChecker component.
Width | Height
Allow you to explicitly define editor dimensions.

Code Example

The code example below demonstrates OnButtonClick and OnCreate event handlers.

The application form’s OnCreate event handler creates two additional embedded buttons in a TcxButtonEdit control and configures the appearance and behavior of all embedded buttons. The OnButtonClick event handler associates all created buttons with the editor’s functionality.

Note

This example uses a TcxImageList component with three SVG icons as a source of glyphs for the created buttons.

procedure TMyForm.cxButtonEdit1PropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var
  AEditor: TcxButtonEdit;
begin
  AEditor := Sender as TcxButtonEdit;
  if AButtonIndex = 0 then  // The first button clears the editor
    AEditor.Clear
  else if AButtonIndex = 1 then  // The second button selects content
    AEditor.SelectAll
  else if AButtonIndex = 2 then  // The third button hides or reveals content
  begin
    if AEditor.Properties.EchoMode = eemNormal then
      AEditor.Properties.EchoMode := eemPassword
    else
      AEditor.Properties.EchoMode := eemNormal;
  end;
end;

procedure TMyForm.FormCreate(Sender: TObject);
var
  AProperties: TcxButtonEditProperties;
  I: Integer;
begin
  cxButtonEdit1.ShowHint := True;  // Enables hints for the editor
  AProperties := cxButtonEdit1.Properties;
  AProperties.BeginUpdate;  // Initiates the following batch change
  try
    AProperties.Images := cxImageList1;  // Assigns the source of button glyphs
    // Create two additional buttons
    AProperties.Buttons.Add;
    AProperties.Buttons.Add;
    // Specify common button settings
    for I := 0 to AProperties.Buttons.Count - 1 do
    begin
      AProperties.Buttons.Items[I].Kind := bkGlyph;  // Changes the button content type to "glyph"
      AProperties.Buttons.Items[I].ImageIndex := I;  // Specifies image indexes in the source list
      AProperties.Buttons.Items[I].HotTrackMode := TcxEditButtonHotTrackMode.Editor;
    end;
    // Specify unique button settings
    AProperties.Buttons.Items[0].Hint := 'Clear';
    AProperties.Buttons.Items[1].Hint := 'Select All';
    AProperties.Buttons.Items[2].Hint := 'Hide/Reveal';
    AProperties.Buttons.Items[2].LeftAlignment := True;
    AProperties.Buttons.Items[2].Transparent := True;
  finally
    AProperties.EndUpdate;  // Calls EndUpdate regardless of the batch operation's success
  end;
end;

VCL Editors Library: An Editor with Three Custom Buttons

Repository Item Class

You can create a TcxEditRepositoryButtonItem component in an edit repository to define an unbound button editor, store button editor settings, and share them between multiple button editors.

Footnotes
  1. Set the following behavior properties to True or False to enable or disable in-place editor hints in corresponding container controls:

See Also