Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder General » View Thread |
Messages 1 to 7 of 7 total |
Integers in TEdits. |
Tue, Jan 24 2012 3:05 AM | Permanent Link |
Steve Gill | Hi Tim,
I've been trying to work out how to validate the TEdit text property to make sure only integers are entered. I found out something interesting (that works): var UserAge: integer; UserAge := StrToInt(edtAge.Text); if IntToStr(UserAge) = 'NaN' then begin // Not a valid number end; Does NaN stand for "Not a Number"? Is this a bug or is this the correct way to check for numbers? Steve |
Tue, Jan 24 2012 4:58 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Steve
Does that work in Delphi as well? If so which version? Normally I've used a try..except block to see if a number was a number. However, I'd generally use the OnKeyPress event to stop anything other than 0..9 being entered. Roy Lambert |
Tue, Jan 24 2012 5:11 AM | Permanent Link |
Walter Matte Tactical Business Corporation | |
Tue, Jan 24 2012 8:01 AM | Permanent Link |
Tim Young [Elevate Software] Elevate Software, Inc. timyoung@elevatesoft.com | Steve,
<< Does NaN stand for "Not a Number"? Is this a bug or is this the correct way to check for numbers? >> This is one of those areas where native Delphi's OP and EWB's OP deviate. If a string isn't a valid number, then you will not receive an exception, rather the result will be NaN. This also applies to floating-point numbers (Double). -- Tim Young Elevate Software www.elevatesoft.com |
Tue, Jan 24 2012 8:06 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Walter
That's totally unrelated to Steve's post. It uses a specialised function (IsNaN) testing numbers. Steve has a StrToInt(string) = 'NaN' but AFAIK in Delphi (up to D2006) doesn't have an overridden version of StrToInt which would produce a string result. Roy Lambert |
Tue, Jan 24 2012 8:50 AM | Permanent Link |
Roy Lambert NLH Associates Team Elevate | Tim
>This is one of those areas where native Delphi's OP and EWB's OP deviate. >If a string isn't a valid number, then you will not receive an exception, >rather the result will be NaN. This also applies to floating-point numbers >(Double). That's what I wanted to know. Nice booby trap Roy Lambert |
Tue, Jan 24 2012 4:03 PM | Permanent Link |
Steve Gill | Hi Tim,
<< This is one of those areas where native Delphi's OP and EWB's OP deviate. If a string isn't a valid number, then you will not receive an exception, rather the result will be NaN. This also applies to floating-point numbers (Double). >> Thanks, makes sense. Yeah, I tried a try..except block first and found it didn't work. Then I put a couple of ShowMessage's in to see what was coming back when I entered a non-number value. Steve |
This web page was last updated on Friday, September 13, 2024 at 03:42 PM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |