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;
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

cbDistance family

cbMass family

cbTemperature family

cbTime family

cbVolume family
Related commands
CelsiusToFahrenheitConvert a celsius temperature into fahrenheit
DegToRadConvert a degrees value to radians
FahrenheitToCelsiusConvert a fahrenheit temperature into celsius
RadToDegConverts a radian value to degrees
TConvFamilyDefines a family of measurement types as used by Convert
TConvTypeDefines a measurement type as used by Convert
 Download this web site as a Windows program.

Example code : Convert UK gallons to litres
  gallons, litres : Double;

  // 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]);
Show full unit code
  1.00 UK gallons = 4.55 litres
Example code : Convert miles per gallon to kilometres per litre
  milesPerGallon, kilometresPerLitre : Double;

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

  // Convert to kilometres per litre
  kilometresPerLitre := Convert(milesPerGallon,

  // Display both values
  ShowMessageFmt('%f UK miles per gallon = %f km per litre',
                 [milesPerGallon, kilometresPerLitre]);
Show full unit code
  58.5 UK miles per gallon = 20.71 km per litre
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page