Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Number is out of range error in Delphi XE6


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Oct 8, 2014 11:42 AM Last Post By: Michael Hackney
Michael Hackney

Posts: 28
Registered: 9/4/14
Number is out of range error in Delphi XE6  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2014 10:24 AM
I'm using an old Paradox database (BDE) along with an older Delphi 6 program I inherited, and it keeps giving me a Number is out of range error when I hit this statement:

POE_Data.OrdersTaxRate.AsFloat:= StrToFloat(Copy(TaxRateLabel.Caption, 1,1));

The TaxRateLabel.Caption equals 7%, and so the StrToFloat is passing just the 7 character. The TaxRate field is defined in the database as a BCD field with 2 decimal places. I don't see any minimum or maximum values set in the database, so why is this producing the number out of range error?
Ian Barker Barker

Posts: 98
Registered: 5/18/07
Re: Number is out of range error in Delphi XE6  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2014 12:56 PM   in response to: Michael Hackney in response to: Michael Hackney
Michael Hackney wrote:

I'm using an old Paradox database (BDE) along with an older Delphi 6
program I inherited, and it keeps giving me a Number is out of range
error when I hit this statement:

POE_Data.OrdersTaxRate.AsFloat:=
StrToFloat(Copy(TaxRateLabel.Caption, 1,1));

The TaxRateLabel.Caption equals 7%, and so the StrToFloat is passing
just the 7 character. The TaxRate field is defined in the database as
a BCD field with 2 decimal places. I don't see any minimum or maximum
values set in the database, so why is this producing the number out
of range error?

Have you tried doing this to see what is actually happening? With it
separated out you can actually inspect the values and see if something
daft is happening. :)

var
  AString: string;
  ADouble: double;
begin
  AString := Copy(TaxRateLabel.Caption, 1,1);
  ADouble := StrToFloat(AString);
  POE_Data.OrdersTaxRate.AsFloat := ADouble;
 
  // also try this - does it cause an error?
  POE_Data.OrdersTaxRate.AsFloat := 1.0;
 
 

--
IanB.
http://about.me/IanBarker

Michael Hackney

Posts: 28
Registered: 9/4/14
Re: Number is out of range error in Delphi XE6  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 7, 2014 1:14 PM   in response to: Ian Barker Barker in response to: Ian Barker Barker
Yes, AString = '7', ADouble = 7, and I still get the error when this line executes: POE_Data.OrdersTaxRate.AsFloat := ADouble; I also tried to substitute this in (POE_Data.OrdersTaxRate.AsFloat := 1.0;), but it also produces the same error.

Ian Barker wrote:
Michael Hackney wrote:

I'm using an old Paradox database (BDE) along with an older Delphi 6
program I inherited, and it keeps giving me a Number is out of range
error when I hit this statement:

POE_Data.OrdersTaxRate.AsFloat:=
StrToFloat(Copy(TaxRateLabel.Caption, 1,1));

The TaxRateLabel.Caption equals 7%, and so the StrToFloat is passing
just the 7 character. The TaxRate field is defined in the database as
a BCD field with 2 decimal places. I don't see any minimum or maximum
values set in the database, so why is this producing the number out
of range error?

Have you tried doing this to see what is actually happening? With it
separated out you can actually inspect the values and see if something
daft is happening. :)

var
  AString: string;
  ADouble: double;
begin
  AString := Copy(TaxRateLabel.Caption, 1,1);
  ADouble := StrToFloat(AString);
  POE_Data.OrdersTaxRate.AsFloat := ADouble;
 
  // also try this - does it cause an error?
  POE_Data.OrdersTaxRate.AsFloat := 1.0;
 
 

--
IanB.
http://about.me/IanBarker

Ian Barker Barker

Posts: 98
Registered: 5/18/07
Re: Number is out of range error in Delphi XE6  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 8, 2014 6:04 AM   in response to: Michael Hackney in response to: Michael Hackney
Michael Hackney wrote:

Yes, AString = '7', ADouble = 7, and I still get the error when this
line executes: POE_Data.OrdersTaxRate.AsFloat := ADouble; I also
tried to substitute this in (POE_Data.OrdersTaxRate.AsFloat := 1.0;),
but it also produces the same error.

Then it seems, to me, that the 'OrdersTaxRate' is not the field type
you thought it was - either at the field level or in the database (the
database schema not matching the persistent in-code field types).

I can't remember if you said you were using table/query components but
if you are...

If you remove and re-add that field the 'orders' table component by
double-clicking on the table and then selecting the dodgy field,
hitting delete. Then save the fields list. Save the changes to the
datamodule/form, CTRL+S, and then double click the component and select
"add fields" and select the missing field again - now does it work?

IanB.
http://about.me/IanBarker
Michael Hackney

Posts: 28
Registered: 9/4/14
Re: Number is out of range error in Delphi XE6  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 8, 2014 11:42 AM   in response to: Ian Barker Barker in response to: Ian Barker Barker
I tried to remove and re-add the table components, but I still got the same result. I then created a new table and a new procedure to post data to the table. With the new procedure I was able to write to a Alpha, Currency, and Number field, but not a BCD field.

Now I changed the field type from BCD to Number and I was able to get that to work without error, but I'm just not sure that's what I want. Time will tell.

Thanks for you assistance!

Ian Barker wrote:
Michael Hackney wrote:

Yes, AString = '7', ADouble = 7, and I still get the error when this
line executes: POE_Data.OrdersTaxRate.AsFloat := ADouble; I also
tried to substitute this in (POE_Data.OrdersTaxRate.AsFloat := 1.0;),
but it also produces the same error.

Then it seems, to me, that the 'OrdersTaxRate' is not the field type
you thought it was - either at the field level or in the database (the
database schema not matching the persistent in-code field types).

I can't remember if you said you were using table/query components but
if you are...

If you remove and re-add that field the 'orders' table component by
double-clicking on the table and then selecting the dodgy field,
hitting delete. Then save the fields list. Save the changes to the
datamodule/form, CTRL+S, and then double click the component and select
"add fields" and select the missing field again - now does it work?

IanB.
http://about.me/IanBarker
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02