Scalabium Software

SMExport advertising

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...

See also
 
SMExport suite
SMImport suite
SMReport
SMDBGrid
MAPIMail
Paradox Viewer
Paradox ActiveX
ExcelFile Viewer
Metafile Convert
DBLoad
DBExport tools
 
 
Contact to webmaster

 

Borland Software Code Gear Scalabium Delphi tips

Copyrightc 1998-2008, Scalabium Software. All rights reserved.
webmaster@scalabium.com

December 2, 2003

SMExport/SMImport suites