Ara*_*ash 9 delphi edit number-formatting
当我在NumbersOnly模式下使用它时,如何更改TEdit的默认错误消息.我是说这个错误:
不可接受的字符您只能在此处键入数字
是否可以更改此消息?
我不知道一个直接的方式来改变该消息的值(它被Windows处理),但你可以展现自己的消息,然后避免以显示原来的窗口提示气球,使用Abort
中的程序OnKeyPress
事件.
检查此样本
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;
Run Code Online (Sandbox Code Playgroud)
您必须知道这些代码将阻止在控件上执行剪贴板操作.
更新
我更新代码以允许Tab(#9)和Back space(#8)字符.