Scalabium Software

SMReport Autogenerated
Knowledge for your independence'.
Home Delphi and C++Builder tips


#160: Numeric editbox

Every developer needs any editbox where end-user can enter only numbers. This is very popular task and you may find a lot of such topics in the public forums/newsgroups.

But most answers in forums are incorrect as I see, because they suggest to write some code in OnKeyPress handler and to check there what is a character pressed.
I say that this code is an incorrect because user could enter any alfa-characters there anyway (via clipboard, for example).

Today I want to post a simple code that allow to solve this task without any problems.
Microsoft have the ES_NUMBER style for any editbox. So all what you need is to send this flag for your editbox:

var
  defstyle: dWord;
begin
  defstyle := GetWindowLong(Edit1.Handle, GWL_STYLE);
  SetWindowLong(Edit1.Handle, GWL_STYLE, defstyle or ES_NUMBER)
end;

If you also want to have a right aligned number, send additionally the ES_RIGHT flag there

It's all - only numeric characters are possible and this is controled on OS level. Hope that you'll like this tip...


Published: December 2, 2003

See also
 
ExcelFile Viewer
Viewer for MS Outlook Messages
Database Information Manager
Paradox Password Recovery
Protected Storage Viewer
SMImport suite
Paradox to MS Access converter
Mail parser (ActiveX)
Paradox to Text converter
SMDBGrid
 
 


Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2023, Scalabium Software. All rights reserved.
webmaster@scalabium.com

SMExport advertising