Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 views
in Technique[技术] by (71.8m points)

Number is out of range error in Delphi XE

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...