Numeric Edit Components

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. 

     

We receive a few cents from each purchase.  Thanks

 


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Mensa® Daily Puzzlers

For over 15 years Mensa Page-A-Day calendars have provided several puzzles a year for my programming pleasure.  Coding "solvers" is most fun, but many programs also allow user solving, convenient for "fill in the blanks" type.  Below are Amazon  links to the two most recent years.

Mensa® 365 Puzzlers  Calendar 2017

Mensa® 365 Puzzlers Calendar 2018

(Hint: If you can wait, current year calendars are usually on sale in January.)

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

 

In the Validating Numeric Input page we discussed the problem of editing numbers entered with the TEdit component.   Although the code works, it's a nuisance to code the event exits for each usage.  I finally decided to implement  visual components to replace TEdit when numbers are entered.  The results are TIntEdit and TFloatEdit visual components.   I'm far from being a component writing expert (nor do I want to be), but these seem to work for me.   

Component authoring is one of the activities that is possible with Delphi Standard but greatly simplified if you own the Pro or Enterprise versions. They  include source code for the entire  Visual Component Library (VCL)  - I would never presume to  write better Delphi code than I could copy from those Borland guys.

They make good introductory components because they are both simple and useful. Both are contained in a single module, NumEdit.pas.  There are about 200 lines of code in the module but 100 of them  just the properties to be published.    The new components are descended from TEdit and I copied the published properties from the source listing for TEdit.  

In addition to re-listing all of the published components of TEdit,  I also added one new property, Value, defined as Int64 for TIntEdit and Extended for TFloatEdit.  It is set by a SetValue procedure and retrieved by a GetValue function .  A  KeyPress exit allows  only valid characters to be entered.    

A Register procedure is required to add the components to the component palette so that you can select and add it to your forms at design time.  I chose the Samples page for the download version, but they live right beside TEdit on the Standard page in my personal Delphi.   NumEdit.dcr  is included in the download to hold the icons displayed on the component palette.  

To install, copy NumEdit.pas and NumEdit.dcr to a library folder, I use the  Lib  folder that comes with Delphi, but you could use any folder that is always be available when you run Delphi.  (The NumEdit.dcu file produced when when you compile the component is the only one that is required when Delphi runs, but I just leave everything in a single folder)    Then  Close All in Delphi, click Component/Install Component and  Browse to select NumEdit.pas.  The  package file name window will probably say dclusr50.dpk (for Delphi 5)  Compile and save  Dclusr50.dpk and you should be ready to use the new components.  Project NumEditTest.dpr is included in the download to provide a simple test of the new components.

Note: The register procedure may fail if you reinstall the components after they have been registered once.  It looks like you can just comment out the  RegisterComponents line in the register procedure. 

Addendum July 6, 2005:  Viewer Luca reminded me that TFloatEdit initialized itself with a value of  "0.0" which of course should be "0,0" for Europeans.  That was fixed today.  

I also created an 2nd version of the controls in unit NumEdit2 which does not require installation of the components before use.   User installed components are a pain because they tend to get left behind with each new computer, operating system, Delphi version installation or reinstallation.   I may have discussed the technique elsewhere, but briefly I prefer to create the controls in the using program and use a prototype standard component to pass location, size, color, exits, etc. to the new control.  In this case, the Create constructors take a TEdit control as the prototype.  Drop a TEdit on the form   as if it were a TIntEdit or TFloatEdit and pass it to the Create constructor for those controls.   Program NumEditTest2 included in NumEdittest2.zip shows how this  works. 

Addendum July 14, 2005:  Oops.  Last week's NumEdit2 upload forgot to initialize the value from the prototype.  Now, if the prototype TEdit has a valid string representation of an integer (TIntEdit) or floating point number (TFloatEdit), that value is transferred, otherwise the new component value is set to zero.    Also added transfer of Anchors property from prototype to the new control. 

Download NumEdit.zip (Installed component version).

Download NumEditTest2.zip (no-installation-required version) 

 

  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright © 2000-2018, Gary Darby    All rights reserved.