System.ConvUtils.RegisterConversionType

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

function RegisterConversionType(AConvTypeInfo: TConvTypeInfo;
out AType: TConvType): Boolean;
function RegisterConversionType(const AFamily: TConvFamily;
const ADescription: string; const AFactor: Double): TConvType;
function RegisterConversionType(const AFamily: TConvFamily;
const ADescription: string; const AToCommonProc,
AFromCommonProc: TConversionProc): TConvType;

C++

extern DELPHI_PACKAGE bool __fastcall RegisterConversionType(TConvTypeInfo* AConvTypeInfo, /* out */ TConvType &AType)/* overload */;

Properties

Type Visibility Source Unit Parent
function public
System.ConvUtils.pas
System.ConvUtils.hpp
System.ConvUtils System.ConvUtils

Description

Registers a new conversion type and returns its identifier.

Call RegisterConversionType to add a new conversion type (unit of measurement) to a registered conversion family. The global Convert function can convert between any two conversion types that have been registered with the same conversion family.

AFamily is the identifier for the conversion family to which the new conversion type belongs. This can be one of the pre-defined conversion families in the StdConvs unit, or the value returned from a call to RegisterConversionFamily.

ADescription is a string that names the conversion type. Typically, this is the plural form of the measurement unit name. For example, the description for the duMeters conversion type is 'Meters'.

AFactor is the factor by which a measurement using the new conversion type must be multiplied to convert to the base units of the conversion family. Thus, for example, the factor for duKilometers is 1000 because the base unit for the distance family is meters.

AToCommonProc and AFromCommonProc are functions that convert between the new conversion type and the base units for the conversion family. They are used when conversions between the new conversion type and the base units can't be accomplished by a simple multiplication. For example, temperature measurements use different values for the 0 point, and so require conversion functions rather than a factor. AToCommonProc converts measurements in the new conversion type to the base units for the family, while AFromCommonProc converts measurements in the base units for the family to the new conversion type.

AConvTypeInfo is an instance of a TConvTypeInfo descendant that represents the new conversion type. On entry, its ConvFamily and Description properties must be set to the conversion family that contains the new conversion type and the string that names the new type (analogous to the AFamily and ADescription parameters). In addition, its ToCommon and FromCommon methods convert between the new conversion type and the base units of the conversion family (analogous to the AToCommonProc and AFromCommonProc parameters). RegisterConversionType sets its ConvType property, which it also returns as the AType parameter. When using this syntax, RegisterConversionType returns true if the new type is successfully registered, false if the new type could not be registered (either because the family was not registered or because the description was already registered).

See Also