ObjectPascal
Convert
Function
Convert one measurement value to another ConvUtils unit
1  function Convert ( const Measurement : Double; const FromType, ToType : TConvType ) : Double;
2  function Convert ( const Measurement : Double; const FromType1, FromType2, ToType1, ToType2 : TConvType ) : Double;
Description
The Convert function is a very powerful and useful measurement utility. It converts a Measurement from one type FromType to another ToType.
 
Version 1
 
Converts simple values such as miles to kilometres.
 
Version 2
 
Converts complex measurements, such as Miles per gallon to Kilometres per litre.
 
All measurement types are TConvType types, and can have an appropriate value from the TConvFamily below. Note that the from and to values must be in the same family.
 
cbArea family
 
  auSquareMillimeters
  auSquareCentimeters
  auSquareDecimeters
  auSquareMeters
  auSquareDecameters
  auSquareHectometers
  auSquareKilometers
  auSquareInches
  auSquareFeet
  auSquareYards
  auSquareMiles
  auAcres
  auCentares
  auAres
  auHectares
  auSquareRods

 
cbDistance family
 
  duMicromicrons
  duAngstroms
  duMillimicrons
  duMicrons
  duMillimeters
  duCentimeters
  duDecimeters
  duMeters
  duDecameters
  duHectometers
  duKilometers
  duMegameters
  duGigameters
  duInches
  duFeet
  duYards
  duMiles
  duNauticalMiles
  duAstronomicalUnits
  duLightYears
  duParsecs
  duCubits
  duFathoms
  duFurlongs
  duHands
  duPaces
  duRods
  duChains
  duLinks
  duPicas
  duPoints

 
cbMass family
 
  muNanograms
  muMicrograms
  muMilligrams
  muCentigrams
  muDecigrams
  muGrams
  muDecagrams
  muHectograms
  muKilograms
  muMetricTons
  muDrams
  muGrains
  muLongTons
  muTons
  muOunces
  muPounds
  muStones

 
cbTemperature family
 
  tuCelsius
  tuKelvin
  tuFahrenheit
  tuRankine
  tuReamur

 
cbTime family
 
  tuMilliSeconds
  tuSeconds
  tuMinutes
  tuHours
  tuDays
  tuWeeks
  tuFortnights
  tuMonths
  tuYears
  tuDecades
  tuCenturies
  tuMillennia
  tuDateTime
  tuJulianDate
  tuModifiedJulianDate

 
cbVolume family
 
  vuCubicMillimeters
  vuCubicCentimeters
  vuCubicDecimeters
  vuCubicMeters
  vuCubicDecameters
  vuCubicHectometers
  vuCubicKilometers
  vuCubicInches
  vuCubicFeet
  vuCubicYards
  vuCubicMiles
  vuMilliLiters
  vuCentiLiters
  vuDeciLiters
  vuLiters
  vuDecaLiters
  vuHectoLiters
  vuKiloLiters
  vuAcreFeet
  vuAcreInches
  vuCords
  vuCordFeet
  vuDecisteres
  vuSteres
  vuDecasteres
  vuFluidGallons
  vuFluidQuarts
  vuFluidPints
  vuFluidCups
  vuFluidGills
  vuFluidOunces
  vuFluidTablespoons
  vuFluidTeaspoons
  vuDryGallons
  vuDryQuarts
  vuDryPints
  vuDryPecks
  vuDryBuckets
  vuDryBushels
  vuUKGallons
  vuUKPottles
  vuUKQuarts
  vuUKPints
  vuUKGills
  vuUKOunces
  vuUKPecks
  vuUKBuckets
  vuUKBushels
Related commands
CelsiusToFahrenheit Convert a celsius temperature into fahrenheit
DegToRad Convert a degrees value to radians
FahrenheitToCelsius Convert a fahrenheit temperature into celsius
RadToDeg Converts a radian value to degrees
TConvFamily Defines a family of measurement types as used by Convert
TConvType Defines a measurement type as used by Convert
 
Example code : Convert UK gallons to litres
var
  gallons, litres : Double;

begin
  // Define the gallons value
  gallons := 1;

  // Convert to litres
  litres := Convert(gallons, vuUKGallons, vuLiters);

  // Display both values
  ShowMessageFmt('%f UK gallons = %f litres',[gallons, litres]);
end;
Show full unit code
   1.00 UK gallons = 4.55 litres
 
Example code : Convert miles per gallon to kilometres per litre
var
  milesPerGallon, kilometresPerLitre : Double;

begin
  // We have a very efficient car
  milesPerGallon := 58.5;

  // Convert to kilometres per litre
  kilometresPerLitre := Convert(milesPerGallon,
                                duMiles,
                                vuUKGallons,
                                duKilometers,
                                vuLiters);

  // Display both values
  ShowMessageFmt('%f UK miles per gallon = %f km per litre',
                 [milesPerGallon, kilometresPerLitre]);
end;
Show full unit code
   58.5 UK miles per gallon = 20.71 km per litre