Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using an old Paradox database along with an older Delphi 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
413 views
Welcome To Ask or Share your Answers For Others

1 Answer

I had a similar problem when updating an old C++Builder project. The solution is to copy the SourcedataData.DB.pas file to your project's code folder and then make the following code change:

procedure TBCDField.SetAsCurrency(Value: Currency);
begin
  if FCheckRange and ((Value < FMinValue) or (Value > FMaxValue)) then
    RangeError(Value, FMinValue, FMaxValue);
//  if FIOBuffer <> nil then
//    TDBBitConverter.UnsafeFrom<System.Currency>(Value, FIOBuffer);
//  SetData(FIOBuffer, False);
  SetData(@Value, False);    // replaces the lines above
end;                         // so can TField.AsBCD

Then add the modified Data.DB.pas file to your project & rebuild your project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...