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

≯℡__Kan透↙ 提交于 2019-12-05 02:03:00

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.

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.

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