|
@@ -43,11 +43,18 @@ Function RegisterConversionType(Fam:TConvFamily;Const S:String;Value:TConvUtilFl
|
|
|
function Convert ( const Measurement : Double; const FromType, ToType : TConvType ) :TConvUtilFloat;
|
|
|
function Convert ( const Measurement : Double; const FromType1, FromType2, ToType1, ToType2 : TConvType ) :TConvUtilFloat;
|
|
|
|
|
|
+function ConvertFrom(const AFrom: TConvType; AValue: Double): TConvUtilFloat;
|
|
|
+
|
|
|
function ConvFamilyToDescription(const AFamily: TConvFamily): string;
|
|
|
function ConvTypeToDescription(const AType: TConvType): string;
|
|
|
+function DescriptionToConvFamily(const ADescription: String; out AFamily: TConvFamily): Boolean;
|
|
|
+function DescriptionToConvType(const ADescription: String; out AType: TConvType): Boolean; overload;
|
|
|
+function DescriptionToConvType(const AFamily: TConvFamily; const ADescription: String; out AType: TConvType): Boolean; overload;
|
|
|
procedure GetConvFamilies(out AFamilies: TConvFamilyArray);
|
|
|
procedure GetConvTypes(const AFamily: TConvFamily; out ATypes: TConvTypeArray);
|
|
|
|
|
|
+function ConvTypeToFamily(const AType: TConvType): TConvFamily;
|
|
|
+
|
|
|
Type
|
|
|
TConvTypeInfo = Class(Tobject)
|
|
|
private
|
|
@@ -109,6 +116,22 @@ begin
|
|
|
result:=TheFamilies[AFamily];
|
|
|
end;
|
|
|
|
|
|
+function DescriptionToConvFamily(const ADescription: String; out AFamily: TConvFamily): Boolean;
|
|
|
+var
|
|
|
+ i: Integer;
|
|
|
+begin
|
|
|
+ Result := False;
|
|
|
+ for i := 0 to Length(TheFamilies) - 1 do
|
|
|
+ begin
|
|
|
+ if TheFamilies[i] = ADescription then
|
|
|
+ begin
|
|
|
+ AFamily := i;
|
|
|
+ Result := true;
|
|
|
+ break;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
procedure GetConvFamilies(out AFamilies: TConvFamilyArray);
|
|
|
|
|
|
var i : integer;
|
|
@@ -145,6 +168,47 @@ Begin
|
|
|
result:=TheUnits[AType].Description;
|
|
|
end;
|
|
|
|
|
|
+function DescriptionToConvType(const ADescription: String; out AType: TConvType): Boolean;
|
|
|
+var
|
|
|
+ i: Integer;
|
|
|
+begin
|
|
|
+ Result := False;
|
|
|
+ for i := 0 to Length(TheUnits) - 1 do
|
|
|
+ begin
|
|
|
+ if TheUnits[i].Description = ADescription then
|
|
|
+ begin
|
|
|
+ AType := i;
|
|
|
+ Result := true;
|
|
|
+ break;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+function DescriptionToConvType(const AFamily: TConvFamily; const ADescription: String; out AType: TConvType): Boolean;
|
|
|
+var
|
|
|
+ i: Integer;
|
|
|
+begin
|
|
|
+ Result := False;
|
|
|
+ for i := 0 to Length(TheUnits) - 1 do
|
|
|
+ begin
|
|
|
+ if (AFamily = TheUnits[i].Fam) and
|
|
|
+ (TheUnits[i].Description = ADescription) then
|
|
|
+ begin
|
|
|
+ AType := i;
|
|
|
+ Result := true;
|
|
|
+ break;
|
|
|
+ end;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+function ConvTypeToFamily(const AType: TConvType): TConvFamily;
|
|
|
+
|
|
|
+begin
|
|
|
+ result:=0; // CIllegalConvFamily according to Tokyo docs.
|
|
|
+ if AType<length(TheUnits) then
|
|
|
+ result:=TheUnits[AType].Fam;
|
|
|
+end;
|
|
|
+
|
|
|
Function RegisterConversionFamily(Const S:String):TConvFamily;
|
|
|
|
|
|
var i,l : Longint;
|
|
@@ -249,6 +313,17 @@ begin
|
|
|
result:=Measurement*(fromrec1.value/fromrec2.value)/(torec1.value/torec2.value);
|
|
|
end;
|
|
|
|
|
|
+function ConvertFrom(const AFrom: TConvType; AValue: Double): TConvUtilFloat;
|
|
|
+
|
|
|
+var
|
|
|
+ fromrec : resourcedata;
|
|
|
+
|
|
|
+begin
|
|
|
+ if not SearchConvert(AFrom, fromrec) then
|
|
|
+ raise EConversionError.CreateFmt(SConvUnknownType, [IntToStr(AFrom)]);
|
|
|
+ result:=fromrec.value*AValue;
|
|
|
+end;
|
|
|
+
|
|
|
Constructor TConvTypeInfo.Create(Const AConvFamily : TConvFamily;const ADescription:String);
|
|
|
|
|
|
begin
|