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

元气小坏坏 提交于 2019-12-10 02:56:11

问题


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 ?


回答1:


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.




回答2:


Looking at the VCL source, it looks like that message is generated by windows, rather than by Delphi. That is, the VCL is only wrapping the functionality that exists in windows. So it doesn't appear that it would be easy to modify the message.



来源:https://stackoverflow.com/questions/6896870/how-can-i-change-the-tedit-default-error-message-numbersonly-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!