From 7da3e17571b49af62db85185272b4284df90c7bd Mon Sep 17 00:00:00 2001 From: marcoonthegit Date: Mon, 6 Jun 2022 23:05:02 +0200 Subject: [PATCH] * Implement ConvUtils.ConvUnitCompareValue and ConvUtils.ConvUnitSameValue bug #39768 --- packages/rtl-objpas/src/inc/convutil.inc | 27 +++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/rtl-objpas/src/inc/convutil.inc b/packages/rtl-objpas/src/inc/convutil.inc index aebfede0fe..7bc6a3ca0c 100644 --- a/packages/rtl-objpas/src/inc/convutil.inc +++ b/packages/rtl-objpas/src/inc/convutil.inc @@ -27,7 +27,7 @@ interface {$ifndef FPUNONE} uses - sysutils; + sysutils, math; Type TConvType = type Integer; TConvFamily = type Integer; @@ -47,6 +47,11 @@ function Convert ( const Measurement : Double; const FromType1, FromType2, ToTy function ConvertFrom(const AFrom: TConvType; AValue: Double): TConvUtilFloat; function ConvertTo(const AValue: Double; const ATo: TConvType): TConvUtilFloat; +function ConvUnitCompareValue(const AValue1: Double; const AType1: TConvType; + const AValue2: Double; const AType2: TConvType): TValueRelationship; +function ConvUnitSameValue(const AValue1: Double; const AType1: TConvType; + const AValue2: Double; const AType2: TConvType): Boolean; + function ConvFamilyToDescription(const AFamily: TConvFamily): string; function ConvTypeToDescription(const AType: TConvType): string; function DescriptionToConvFamily(const ADescription: String; out AFamily: TConvFamily): Boolean; @@ -112,6 +117,7 @@ Type ResourceData = record var TheUnits : array of ResourceData =nil; TheFamilies : array of string =nil; + function ConvFamilyToDescription(const AFamily: TConvFamily): string; begin @@ -371,6 +377,25 @@ begin result:=Avalue/torec.value; end; +function ConvUnitCompareValue(const AValue1: Double; const AType1: TConvType; + const AValue2: Double; const AType2: TConvType): TValueRelationship; + +var + D1, D2: TConvUtilFloat; + +begin + D1:=ConvertFrom(AType1, AValue1); + D2:=ConvertFrom(AType2, Avalue2); + result:=CompareValue(D1,D2,macheps); +end; + +function ConvUnitSameValue(const AValue1: Double; const AType1: TConvType; + const AValue2: Double; const AType2: TConvType): Boolean; +begin + result:=ConvUnitCompareValue(Avalue1, AType1, AValue2, AType2)=0; +end; + + Constructor TConvTypeInfo.Create(Const AConvFamily : TConvFamily;const ADescription:String); begin