Sign in Join
Wiki copytemporary

TMaskEdit: what changed

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

OldNewLine
11A **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]].
22
33## The EditMask property
44
55The EditMask consist of 3 fields, each separated by the MaskFieldSeparator character (by default a semicolon (';')).
66
77| | | | |
88|----|----|----|----|
99| **Field** | **Type** | **Meaning** | **Required** |
1010| Actual mask | String | The actual pattern to which the text has to fit | Yes |
1111| 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 |
1212| SpaceChar | Char | The character shown in the TMaskEdit when left blank. Defaults to '_' | No |
1313
1414The actual mask is formed with a pattern of characters with the following meaning:
1515
1616| | | | |
1717|----|----|----|----|
1818| **Type** | **Character** | **Possible input by user** | **Delphi compatibility** |
1919| cMask_SpecialChar | \\ | after this you can set an arbitrary char (e.g. for unit like 'P\a' =\> 'Pa') | |
2020| cMask_LowerCase | \< | after this the chars is in lower case | |
2121| cMask_UpperCase | \> | after this the chars is in upper case. Notice that the sequence \<\> will end enforcing lower- or uppercase. | |
2222| cMask_Letter | l | only a letter but not necessary | |
2323| cMask_LetterFixed | L | only a letter (arbitrary!) | |
2424| cMask_AlphaNum | a | an alphanumeric char (\['A'..'Z','a..'z','0'..'9'\]) but not necessary | |
2525| cMask_AlphaNumFixed | A | an alphanumeric char (arbitrary!) | |
2626| cMask_AllChars | c | any Utf8 char but not necessary | |
2727| cMask_AllCharsFixed | C | any Utf8 char, but NOT SpaceChar | |
2828| cMask_Number | 9 | only a number but not necessary \[('0'..'9'\]) | |
2929| cMask_NumberFixed | 0 | only a number (arbitrary!) | |
3030| cMask_NumberPlusMin | \# | only a number \[('0'..'9'\]) or '+' or '-', but not necessary | |
3131| cMask_HourSeparator | : | automatically put the hour separator char | |
3232| cMask_DateSeparator | / | automatically put the date separator char | |
3333| cMask_Hex | h | a hexadecimal character but not necessary | Lazarus extension, not supported by Delphi |
3434| cMask_HexFixed | H | a hexadecimal character | Lazarus extension, not supported by Delphi |
3535| cMask_Binary | b | a binary character but not necessary | Lazarus extension, not supported by Delphi |
3636| cMask_BinaryFixed | B | a binary character | Lazarus extension, not supported by Delphi |
3737| cMask_SetStart | \[ | Start of a set (if EnableSets = True) | Lazarus extension, not supported by Delphi |
3838| cMask_SetEnd | \] | End of a set (if EnableSets = True) | Lazarus extension, not supported by Delphi |
3939| cMask_SetNegate | ! | Negates a set (if it is the first character inside the given set) | Lazarus extension, not supported by Delphi |
4040| 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 |
4141| cMask_NoLeadingBlanks | ! | Trim leading blanks, otherwise trim trailing blanks from the data | |
4242
4343## Avoiding Exceptions upon validation
4444
45-When the user leaves the TMaskEdit (or presses <span class="kbd">Enter</span>) the control validates the input against the EditMask.\
45+When the user leaves the TMaskEdit (or presses `Enter`) the control validates the input against the EditMask.\
4646By default, if validation fails, an `EDBEditError` exception will be raised.\
4747If you want to handle this exception, you'll need to do this in the [[TApplication|Application's]] `OnException` event.\
4848You can avoid exceptions on validation if you set the `ValidationErrorMode` property to `mvemEvent` and handle the validation error in the TMaskEdit's `OnValidationError` event.\
4949Notice that this is a Lazarus extension of TMaskEdit and it is **not** Delphi compatible.
5050
5151## Sample EditMask files
5252
5353The property editor for TMaskEdit.EditMask supports the loading of sample files.\
5454Delphi 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.\
5555The latter has a more relaxed syntax, where whitespace is non-significant (in other words: it will be ignored).\
5656For copyrigth reasons Lazarus does not distribute sample editmask files itself.
5757
5858### Syntax of sample EditMask files
5959
6060Sample EditMask files are plain text files, where each line defines a sample editmask.\
6161Each 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.\
6262Lines starting with `//` will be ignored. You can use this feature to add comments to your sample editmask file(s).\
6363Notice that Lazarus assumes the file is UTF-8 encoded.
6464
6565| | |
6666|----|----|
6767| **Fieldname** | **Meaning** |
6868| Caption | The name of the sample editmask as displayed in the property editor |
6969| Example | Example text applied to the editmask (*) |
7070| EditMask | Sample editmask |
7171
7272* 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.\
7373Consider the following line in a sample file:\
7474`IPv4 value | 128255255032 | !999.999.999.999;1;_`\
7575This will show "IPv4 value" as caption and "128.255.255.032" as an example in the property editors listbox (without the quotes obviously).
7676
7777## See also
7878
7979- [[doc:lcl/maskedit/tmaskedit.html|TMaskEdit doc]]
8080- [[TEdit]] - A basic field
8181- [[TLabeledEdit]] - An edit field like a TEdit with a label
8282- [[TSpinEdit]] - An edit field for integers defined numbers range limits
8383- [[TFloatSpinEdit]] - An edit field for tiles floating-point numbers with defined numbers range limits
8484- [[TEditButton]] - An edit field like a TEdit with an attached button as a [[TSpeedBtn]]
8585- [[TFileNameEdit]] - An edit field with attached [[TOpenDialog]], to enter a file name
8686- [[TDirectoryEdit]] - An edit field with attached [[TSelectDirectoryDialog]], to enter a file path
8787- [[TDateEdit]] - An edit field with attached [[TCalendarDialog]] (calendar), to enter a date
8888- [[TCalcEdit]] - An input field with attached [[TCalculatorDialog]] (Calculator), to enter a number
8989- [[TTIEdit]] - An RTTI capable input field
9090
9191---
9292*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