Sign in Join
Wiki copytemporary

TMaskEdit: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: TMaskEdit

OldNewLine
1+A **TMaskEdit** ![](/wiki-images/8/88/Tmaskedit.png) is a control with a single line of editable text that has to fit to a predefined 'EditMask'. It is available from the [[Additional tab]] of the [[Component Palette]].
2+
3+## The EditMask property
4+
5+The EditMask consist of 3 fields, each separated by the MaskFieldSeparator character (by default a semicolon (';')).
6+
7+| | | | |
8+|----|----|----|----|
9+| **Field** | **Type** | **Meaning** | **Required** |
10+| Actual mask | String | The actual pattern to which the text has to fit | Yes |
11+| MaskSave | Char | Controls wether the Text property contains the literals in the actual mask. A value other than '0' means literals will be included. | No |
12+| SpaceChar | Char | The character shown in the TMaskEdit when left blank. Defaults to '_' | No |
13+
14+The actual mask is formed with a pattern of characters with the following meaning:
15+
16+| | | | |
17+|----|----|----|----|
18+| **Type** | **Character** | **Possible input by user** | **Delphi compatibility** |
19+| cMask_SpecialChar | \\ | after this you can set an arbitrary char (e.g. for unit like 'P\a' =\> 'Pa') | |
20+| cMask_LowerCase | \< | after this the chars is in lower case | |
21+| cMask_UpperCase | \> | after this the chars is in upper case. Notice that the sequence \<\> will end enforcing lower- or uppercase. | |
22+| cMask_Letter | l | only a letter but not necessary | |
23+| cMask_LetterFixed | L | only a letter (arbitrary!) | |
24+| cMask_AlphaNum | a | an alphanumeric char (\['A'..'Z','a..'z','0'..'9'\]) but not necessary | |
25+| cMask_AlphaNumFixed | A | an alphanumeric char (arbitrary!) | |
26+| cMask_AllChars | c | any Utf8 char but not necessary | |
27+| cMask_AllCharsFixed | C | any Utf8 char, but NOT SpaceChar | |
28+| cMask_Number | 9 | only a number but not necessary \[('0'..'9'\]) | |
29+| cMask_NumberFixed | 0 | only a number (arbitrary!) | |
30+| cMask_NumberPlusMin | \# | only a number \[('0'..'9'\]) or '+' or '-', but not necessary | |
31+| cMask_HourSeparator | : | automatically put the hour separator char | |
32+| cMask_DateSeparator | / | automatically put the date separator char | |
33+| cMask_Hex | h | a hexadecimal character but not necessary | Lazarus extension, not supported by Delphi |
34+| cMask_HexFixed | H | a hexadecimal character | Lazarus extension, not supported by Delphi |
35+| cMask_Binary | b | a binary character but not necessary | Lazarus extension, not supported by Delphi |
36+| cMask_BinaryFixed | B | a binary character | Lazarus extension, not supported by Delphi |
37+| cMask_SetStart | \[ | Start of a set (if EnableSets = True) | Lazarus extension, not supported by Delphi |
38+| cMask_SetEnd | \] | End of a set (if EnableSets = True) | Lazarus extension, not supported by Delphi |
39+| cMask_SetNegate | ! | Negates a set (if it is the first character inside the given set) | Lazarus extension, not supported by Delphi |
40+| cMask_SetOptional | \| | Makes the set optional, so a blank is accepted (if it is the first character inside the given set, and the set is not negated) | \| Lazarus extension, not supported by Delphi |
41+| cMask_NoLeadingBlanks | ! | Trim leading blanks, otherwise trim trailing blanks from the data | |
42+
43+## Avoiding Exceptions upon validation
44+
45+When the user leaves the TMaskEdit (or presses <span class="kbd">Enter</span>) the control validates the input against the EditMask.\
46+By default, if validation fails, an `EDBEditError` exception will be raised.\
47+If you want to handle this exception, you'll need to do this in the [[TApplication|Application's]] `OnException` event.\
48+You can avoid exceptions on validation if you set the `ValidationErrorMode` property to `mvemEvent` and handle the validation error in the TMaskEdit's `OnValidationError` event.\
49+Notice that this is a Lazarus extension of TMaskEdit and it is **not** Delphi compatible.
50+
51+## Sample EditMask files
52+
53+The property editor for TMaskEdit.EditMask supports the loading of sample files.\
54+Delphi sample editmask files (*.dem) were already supported for a long time and in Lazarus 4.0 support for Lazarus sample editmask files (*.lem) was added.\
55+The latter has a more relaxed syntax, where whitespace is non-significant (in other words: it will be ignored).\
56+For copyrigth reasons Lazarus does not distribute sample editmask files itself.
57+
58+### Syntax of sample EditMask files
59+
60+Sample EditMask files are plain text files, where each line defines a sample editmask.\
61+Each line consists of 3 fields separated by a pipe symbol. In Delpi sample files (*.dem) each pipe symbol must be preceeded and followed by a space.\
62+Lines starting with `//` will be ignored. You can use this feature to add comments to your sample editmask file(s).\
63+Notice that Lazarus assumes the file is UTF-8 encoded.
64+
65+| | |
66+|----|----|
67+| **Fieldname** | **Meaning** |
68+| Caption | The name of the sample editmask as displayed in the property editor |
69+| Example | Example text applied to the editmask (*) |
70+| EditMask | Sample editmask |
71+
72+* When applying the example text, the sample editmask's MaskSave and SpaceChar fields will be ignored (and set to False and a space char (#32) respectively). This is done for Delphi compatibility.\
73+Consider the following line in a sample file:\
74+`IPv4 value | 128255255032 | !999.999.999.999;1;_`\
75+This will show "IPv4 value" as caption and "128.255.255.032" as an example in the property editors listbox (without the quotes obviously).
76+
77+## See also
78+
79+- [[doc:lcl/maskedit/tmaskedit.html|TMaskEdit doc]]
80+- [[TEdit]] - A basic field
81+- [[TLabeledEdit]] - An edit field like a TEdit with a label
82+- [[TSpinEdit]] - An edit field for integers defined numbers range limits
83+- [[TFloatSpinEdit]] - An edit field for tiles floating-point numbers with defined numbers range limits
84+- [[TEditButton]] - An edit field like a TEdit with an attached button as a [[TSpeedBtn]]
85+- [[TFileNameEdit]] - An edit field with attached [[TOpenDialog]], to enter a file name
86+- [[TDirectoryEdit]] - An edit field with attached [[TSelectDirectoryDialog]], to enter a file path
87+- [[TDateEdit]] - An edit field with attached [[TCalendarDialog]] (calendar), to enter a date
88+- [[TCalcEdit]] - An input field with attached [[TCalculatorDialog]] (Calculator), to enter a number
89+- [[TTIEdit]] - An RTTI capable input field
90+
91+---
92+*From the Free Pascal wiki, page "TMaskEdit", as it stood on 2024-05-20 after a change by Bart, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history