FMX.Edit.TCustomEdit.OnValidating
Delphi
property OnValidating: TValidateTextEvent read GetOnValidating write SetOnValidating;
C++
__property Fmx::Text::TValidateTextEvent OnValidating = {read=GetOnValidating, write=SetOnValidating};
Contents
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
event | public | FMX.Edit.pas FMX.Edit.hpp |
FMX.Edit | TCustomEdit |
Description
Occurs when you are entering symbols or when focus shifts away from this edit control.
Write an OnValidating event handler to immediately validate any edits while the user is entering information into the edit control. The OnValidating event handler can verify the supplied text and, if it is not acceptable, return an error or warning message.
Example
To clarify, consider the following scenario: an application provides a text edit box designed to enter an email address. If the user enters the blank character or the "@." substring, the OnValidating event handler displays the exclamation icon next to the edit control. This icon informs the user that the current symbols are not acceptable for the email address.
Note: Initially, the exclamation icon is invisible. The OnValidating event handler sets the TImage.Visible property to
True
, if an input error occurs.
For this scenario, you can implement the following OnValidating event handlers:
Delphi:
procedure TForm1.Edit1Validating(Sender: TObject; var Text: string);
begin
Image1.Visible := Text.Contains(' ') or Text.Contains('@.');
end;
C++Builder:
void __fastcall TForm1::Edit1Validating(TObject *Sender, UnicodeString &Text) {
Image1->Visible = ContainsStr(Text, " ") || ContainsStr(Text, "@.");
}
Note: To process the user's input, these code snippets use:
- For C++Builder: the System.StrUtils.ContainsStr routine.
- For Delphi: the System.SysUtils.TStringHelper.Contains methode.