Get access to over 100 FireMonkey cross platform samples for Android, IOS, OSX, Windows, and Linux!

AndroidAppmethodCode SnippetDelphiFiremonkeyIOSOSXWindows

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.

Related posts
AndroidC++BuilderDelphiDemoFiremonkeyWindows

Powerful Commercial Gorilla3D Framework Upgraded For Delphi FireMonkey On Windows And Android

AndroidC++BuilderCode SnippetDelphiDemoFiremonkeyIOSOSXShowcaseWindows

Powerful Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

AndroidC++BuilderDelphiFiremonkeyIOSOSXWindows

Significant Update Available For Delphi FireMonkey 10.4.1 On Android, IOS, OSX, Windows, And Linux

C++BuilderDelphiIDEWindows

Professional SVG Icon Image List For Delphi 10.4 FireMonkey On Windows

Sign up for our Newsletter and
stay informed

1 Comment

Leave a Reply to João Bemgiz Cordeiro Cancel reply