Parent Controls And TEdit TextPrompt Workaround In Delphi XE7 Firemonkey On Android And IOS

Delphi XE7 Firemonkey TEdit TextPrompt Workaround FixThere is an issue with the TextPrompt property of TEdit in Delphi XE7 Firemonkey where it does not show up. According to the Quality Central report on the problem it has already been fixed and will probably be part the next update. However, this is an opportunity to highlight just how powerful Firemonkey can be by allowing any control to be parented by any other control. Don’t get hung up thinking that there is only one way to solve a problem. In traditional VCL only the TPanel or third party components allowed a component to be inside of another component (with some exceptions). With Firemonkey you can take a button or a label and put it inside of another button or label or edit control. With this in mind if you would like to build your own TextPrompt functionality you can simply take a TLabel and place it inside of your TEdit control. Change the HitTest property of the TLabel to False so that it allows all mouse or tap events to pass through it to the TEdit control. Set the Align property of the TLabel to Content or Client. Content fills the parent control regardless of any other child controls and Client fills the parent control but makes space for other aligned child controls. Next add code into the OnChange/OnKeyUp event (and/or the OnTyping event) which shows or hides the TLabel based on if TEdit is empty or not. If you want to get fancy you could put a semi transparency on the TLabel with the Opacity property or by changing it’s color to a lighter grey color. This parenting functionality of Firemonkey controls works cross platform on Android, IOS, Windows, and OSX. I recommend using this TLabel method instead of the TextPrompt property in Delphi XE5 and Delphi XE6 as well.

Head over and check out an article on the Embarcadero docwiki about arranging and parenting controls in Firemonkey.

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

Parent Controls And TEdit TextPrompt Workaround In Delphi XE7 Firemonkey On Android And IOS by Delphi XE5 XE6 XE7 XE8 10 Seattle Berlin Firemonkey, Delphi Android, Delphi IOS is licensed under a Creative Commons Attribution 4.0 International License.

One Response to Parent Controls And TEdit TextPrompt Workaround In Delphi XE7 Firemonkey On Android And IOS

  1. jeffam70 says:

    Excellent point. Thanks for the little tutorial!

Leave a Reply

Show Buttons
Hide Buttons
Read previous post:
Delphi XE7 Firemonkey NFC Android Tutorial JAR
Tutorial On How To Build NFC Functionality Into Your Delphi XE7 Firemonkey Apps On Android

Developers Daniel Magin and Brian Long teamed up to create a solution for enabling NFC access from Delphi XE7 Firemonkey....

Close