* Implement ConvUnitAdd, ConvUnitDiff, ConvUnitInc and ConvUnitDec bug #39769

(cherry picked from commit 7886233b0e)
This commit is contained in:
marcoonthegit 2022-06-06 23:10:14 +02:00
parent 3c778ccfb6
commit 826c0cc17c

View File

@ -52,6 +52,18 @@ function ConvUnitCompareValue(const AValue1: Double; const AType1: TConvType;
function ConvUnitSameValue(const AValue1: Double; const AType1: TConvType;
const AValue2: Double; const AType2: TConvType): Boolean;
function ConvUnitAdd(const AValue1: Double; const AType1: TConvType;
const AValue2: Double; const AType2, AResultType: TConvType): TConvUtilFloat;
function ConvUnitDiff(const AValue1: Double; const AType1: TConvType;
const AValue2: Double; const AType2, AResultType: TConvType): TConvUtilFloat;
function ConvUnitDec(const AValue: Double; const AType: TConvType;
const AAmount: Double; const AAmountType: TConvType): TConvUtilFloat;
function ConvUnitDec(const AValue: Double; const AType, AAmountType: TConvType): TConvUtilFloat;
function ConvUnitInc(const AValue: Double; const AType: TConvType;
const AAmount: Double; const AAmountType: TConvType): TConvUtilFloat;
function ConvUnitInc(const AValue: Double; const AType, AAmountType: TConvType): TConvUtilFloat;
function ConvFamilyToDescription(const AFamily: TConvFamily): string;
function ConvTypeToDescription(const AType: TConvType): string;
function DescriptionToConvFamily(const ADescription: String; out AFamily: TConvFamily): Boolean;
@ -117,6 +129,37 @@ Type ResourceData = record
var TheUnits : array of ResourceData =nil;
TheFamilies : array of string =nil;
function ConvUnitDec(const AValue: Double; const AType: TConvType;
const AAmount: Double; const AAmountType: TConvType): TConvUtilFloat;
var
D1: Double;
begin
D1:=Convert(AAmount,AAmountType,AType);
result:=AValue-D1;
end;
function ConvUnitDec(const AValue: Double; const AType, AAmountType: TConvType): TConvUtilFloat;
begin
result:=ConvUnitDec(AValue, AType, 1.0, AAmountType);
end;
function ConvUnitInc(const AValue: Double; const AType: TConvType;
const AAmount: Double; const AAmountType: TConvType): TConvUtilFloat;
var
D1: Double;
begin
D1:=Convert(AAmount,AAmountType,AType);
result:=AValue+D1;
end;
function ConvUnitInc(const AValue: Double; const AType, AAmountType: TConvType): TConvUtilFloat;
begin
result:=ConvUnitInc(AValue, AType, 1.0, AAmountType);
end;
function ConvFamilyToDescription(const AFamily: TConvFamily): string;
@ -396,6 +439,24 @@ begin
end;
function ConvUnitAdd(const AValue1: Double; const AType1: TConvType;
const AValue2: Double; const AType2, AResultType: TConvType): TConvUtilFloat;
var
D1, D2: Double;
begin
D1:=ConvertFrom(AType1, AValue1);
D2:=ConvertFrom(AType2,AValue2);
result:=ConvertTo(D1+D2,AResultType);
end;
function ConvUnitDiff(const AValue1: Double; const AType1: TConvType;
const AValue2: Double; const AType2, AResultType: TConvType): TConvUtilFloat;
begin
result:=ConvUnitAdd(AVAlue1, ATYpe1, -AValue2, AType2, AResultType);
end;
Constructor TConvTypeInfo.Create(Const AConvFamily : TConvFamily;const ADescription:String);
begin