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
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
 Author links

 Buy Website Traffic at

 Buy Proxies at
 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
// Full Unit code.
// -----------------------------------------------------------
// You must store this code in a unit called Unit1 with a form
// called Form1 that has an OnCreate event called FormCreate.
unit Unit1;
  ConvUtils,   // Unit containing the Convert command
  Forms, Dialogs;
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
Form1: TForm1;
{$R *.dfm} // Include form definitions
procedure TForm1.FormCreate(Sender: TObject);

  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]);
Hide full unit code
   58.5 UK miles per gallon = 20.71 km per litre
Delphi Programming Neil Moffatt 2002 - 2017. All rights reserved.  |  Home Page