PeterDelphin
asked on
Validate TEdit to allow only valid file name characters?
Hi! In a Delphi XE7 VCL application, at runtime I need to validate the text input inside a TEdit to allow only valid file name characters. In Delphi XE7 there is the System.IOUtils.TPath.HasVa lidFileNam eChars function. How can this be applied in real-time in a TEdit component?
Unfortunately, the TEdit component has no OnValidating event. I don't want to use the OnChange event, because it looks ugly when the character appears for a short time. The validation must occur BEFORE the character appears.
Unfortunately, the TEdit component has no OnValidating event. I don't want to use the OnChange event, because it looks ugly when the character appears for a short time. The validation must occur BEFORE the character appears.
ASKER
This is not reliable, as one can paste still PASTE chars which are not allowed as filename.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
procedure TForm1.Edit1KeyPress(Sende
begin
if Key in ['a'..'z', 'A'..'Z','\', ..etc] // List all the allowed Char ranges
if not TPath.HasValidFileNameChar
Key:= #0;
end;