How To Make a TEdit numeric

A small tip showing how to tell windows that your Edit control should only allow numeric entry.

If you need a Windows Edit control to only accept valid numbers, but don't want to use TSpinEdit, here is a simple piece of code which will allow you to alter the behaviour of a standard Windows Edit control.

procedure MakeNumericOnly(Handle: THandle);
begin
SetWindowLong(Handle, GWL_STYLE,
GetWindowLong(Handle, GWL_STYLE) or ES_NUMBER);
end;

 

Share this article!

Follow us!

Find more helpful articles: