Create A Custom Mask Edit Validation Event In Delphi XE7 Firemonkey On Android And IOS

Delphi XE7 Firemonkey Mask EditIf you are doing any kind of validation of fields with a TEdit component in Delphi XE7 Firemonkey you may be looking for a TMaskEdit control. Delphi VCL has a TMaskEdit but Firemonkey on Android, IOS, Windows, and Mac does not ship with one. This is easily solved however with some custom code in the OnKeyDown event. Basically the general idea is that when the user presses a key you check the key being pressed and the contents of the edit to see if it matches what you want it to accept. If the key should not be allowed you set it’s value to #0. I adapted my code snippet from a Delphi VCL example. One item of note is that I use String.IndexOf() in the code snippet which has cross platform support verses the Pos() function which gives you different values depending on if it is a mobile platform (0 based) or a desktop platform (1 based). This code snippet is really just to get you started with a mask edit solution. There are other things you will need to take into account as well like for example on Android the user can select entire auto complete words from the keyboard. You’ll have to come up with your own code for the OnChange event to handle those. TMS Pack for Firemonkey also has some edit components that support masking. The code snippet sample below shows how to filter for a decimal. It should also work in Appmethod.

Check out a Delphi VCL example of creating a custom masked edit for Delphi VCL and then adapt the code to Firemonkey yourself.

Have Delphi Firemonkey questions? Ask and get answers on StackOverflow.

One Response to Create A Custom Mask Edit Validation Event In Delphi XE7 Firemonkey On Android And IOS

  1. The HTML changed the code … The correct code is :

    if (KeyChar=’.’) AND (MyEdit.Text.IndexOf(‘.’)>-1) then


Leave a Reply

Show Buttons
Hide Buttons
Read previous post:
Design And Build Your Own Components For Delphi XE7 Firemonkey On Android And IOS

Embarcadero has a section in the Firemonkey documentation about how to build components. There are three initial sections which over...