[Overview][Constants][Types][Classes][Procedures and functions][Index] | Reference for unit 'MaskEdit' (#lcl)

# TCustomMaskEdit

[Properties (by Name)] [Methods (by Name)] [Events (by Name)]

The base class for TMaskEdit.

## Declaration

Source position: maskedit.pp line 206

`type TCustomMaskEdit = class(TCustomEdit)`
`protected`
`class procedure WSRegisterClass; override;` |  | Registers the widget set class reference used to create new instances of the control.
`function ApplyMaskToText();` |  | Applies the edit mask in the control to the specified value.
`function CanShowEmulatedTextHint; override;` |  | Indicates if the control can display its Hint or TextHint using the LCL capability layer.
`function DisableMask();` |  | Saves and disables the edit mask in the control.
`procedure DoValidationError;` |  | Performs actions when the control value is invalid for its edit mask.
`function RestoreMask();` |  | Restores the saved edit mask in the control.
`procedure RealSetText(); override;` |  | Sets the value for the Text in the control.
`function RealGetText; override;` |  | Gets the value for the Text in the control.
`function GetTextWithoutMask();` |  | Gets the text value for the control without formatting applied by an edit mask.
`function GetTextWithoutSpaceChar();` |  | Gets the value for the control without the Space character literal used in the edit mask.
`procedure SetTextApplyMask();` |  | Sets the value for the control after applying its edit mask.
`function GetEditText; virtual;` |  | Gets the value for the EditText property.
`procedure SetEditText();` |  | Sets the value for the EditText property.
`procedure GetSel();` |  | Finds the starting and ending positions for the selection.
`procedure SetSel();` |  | Specifies the starting and ending positions for the text selected in the control.
`procedure TextChanged; override;` |  | Performs actions when the value in the Text property has been changed.
`procedure Change; override;` |  | Suppresses the OnChange event when the initial value for the control is assigned.
`procedure SetCharCase(); override;` |  | Sets the value in the CharCase property.
`procedure SetMaxLength();` |  | Sets the value for the MaxLength property.
`function GetMaxLength;` |  | Gets the value for the MaxLength property.
`procedure SetNumbersOnly(); override;` |  | Sets the value for the NumbersOnly property.
`procedure Loaded; override;` |  | Performs actions when a component has been loaded from the LCL streaming mechanism.
`procedure LMPasteFromClip(); message;` |  | LMPasteFromClip is the LCL message method for pasting from the clipboard.
`procedure LMCutToClip(); message;` |  | LMCutToClip is the LCL message method for cutting to the clipboard.
`procedure LMClearSel(); message;` |  | LMClearSel is the LCL message method for clearing selected items.
`function EditCanModify; virtual;` |  | If True, the Edit box is allowed to modify its contents.
`procedure Reset; virtual;` |  | Reset returns the edit to its default state with mask appearing in Text box and no string input.
`procedure DoEnter; override;` |  | Performs actions needed when the control is entered.
`procedure DoExit; override;` |  | Performs actions needed when the control is exited.
`procedure KeyDown(); override;` |  | Performs actions needed to apply key down messages.
`procedure HandleKeyPress();` |  | Handle all keys from KeyPress and Utf8KeyPress.
`procedure KeyPress(); override;` |  | Performs actions needed to handle the specified character in the control.
`procedure Utf8KeyPress(); override;` |  | Handles a key press with the specified UTF-8 character value.
`procedure MouseUp(); override;` |  | Performs actions needed to handle a mouse button up message.
`procedure CheckCursor;` |  | Updates the position for the cursor (or caret) when an EditMask is used in the control.
`property EditText: string; [rw]` |  | Value entered in the control and obscured / formatted using the EditMask.
`property IsMasked: Boolean; [r]` |  | True if a non-empty value has been assigned to EditMask.
`property SpaceChar: Char; [rw]` |  | Contains the value used to represent Space (#32) characters in the control value.
`property MaxLength: Integer; [rw]` |  | Indicates the maximum number of characters that can be stored in the value for the control.
`property EditMask: string; [rw]` |  | Contains the mask characters classes and literals used to format/obscure the value for the control.
`public`
`procedure CutToClipBoard; override;` |  | Moves the selected text into the clipboard (removes it from the control).
`procedure PasteFromClipBoard; override;` |  | Inserts text from the clipboard at the current position in the control.
`constructor Create(); override;` |  | Constructor for the class instance.
`procedure Clear;` |  | Clears the value for the edit control.
`procedure SelectAll; override;` |  | Selects all of the text in the masked edit control.
`procedure ValidateEdit; virtual;` |  | Validates the value for the edit control when an EditMask has been specified.
`property EnableSets: Boolean; [rw]` |  | Enables or disables use of set notation in the EditMask.
`property ValidationErrorMode: TMaskEditValidationErrorMode; [rw]` |  | Indicates the action taken when the control value is invalid for its mask.
`property Modified: Boolean; [rw]` |  | Indicates if the value for the edit control has been changed.
`property OnValidationError: TNotifyEvent; [rw]` |  | Event handler signalled when the value for the masked edit control is invalid.
`end;`

## Inheritance

`TCustomMaskEdit` |  | The base class for TMaskEdit.
`TCustomEdit` |  | The base class for controls presenting editable text.
`TWinControl` |  | Implements a windowed control which can contain other child controls.
`TControl` |  | The base class for visible controls.
`TLCLComponent` |  | The base class for LCL components which have an associated widget.
`TComponent`
?
`TObject`

## Description

TCustomMaskEdit is a TCustomEdit descendant, and the base class for TMaskEdit. TCustomMaskEdit provides an Edit box with masking features for characters displayed (or hidden) in the control.

Remark: | FOR ANYONE WHO CARES TO FIX / ENHANCE THIS CODE:

Since we want total control over anything that is done to the text in the control, we have to take into consideration the fact that currently we cannot prevent cutting/pasting/clearing or dragging selected text in the control. These operations are handled by the OS, and text is changed before we can prevent it. Not all widgetsets currently handle the messages for cut/paste/clear. Actually, we would like to have a LM_BEFORE_PASTE (etc.) message... If we allow the OS to cut/clear/paste etc. A situation can occur where mask-literals in the control are changed to random characters (which cannot be undone), or text is shorter or larger than the editmask calls for, which again cannot be undone.

So, as a horrible hack, I decided to only allow changing the text if we coded this change ourself. This is done by setting the FChangeAllowed field to True before any write action (in RealSetTextWhileMasked() ). We try to intercept the messages for cut/paste/copy/clear and perform the appropriate actions instead. If this fails, then in TextChanged we check and will see that FChangeAllowed = False and we will undo the changes made.

To make this undo possible, it is necessary to set FCurrentText every time you set the text in the control! This is achieved in RealSetTextWhileMasked() only.

Remark: | It is unsafe to make a call to RealSetText unless done so via RealSetTextWhileMasked!!!

Bart Broersma, January 2009