Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change the TEdit default error message (NumbersOnly mode)?

How can I change the TEdit's default error message when I use it in NumbersOnly mode. I mean this error:

Unacceptable character You can only type a number here

Is it possible to change this message ?

like image 890
Arash Avatar asked Aug 01 '11 10:08

Arash


1 Answers

I don't know a direct way to change the value of that message (which is handled by Windows) but you can show your own message and then avoid to show the original windows hint ballon, using the Abort procedure in the OnKeyPress Event.

Check this sample

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if not (CharInSet(Key,['0'..'9',#8,#9]))  then      
  begin
    ShowHintMessage('Only numbers please');//you must write this function 
    Abort;//this will prevent which the original windows hint was shown
  end;
end;

You must we aware which this code will be prevent the execution of the clipboard operations over the control.

Update

I Update the code to allow the Tab(#9) and Back space(#8) chars.

like image 70
RRUZ Avatar answered Sep 27 '22 22:09

RRUZ