RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
ConvUtils.DescriptionToConvType Function

Retrieves the identifier for a conversion type given its name and family.

Pascal
function DescriptionToConvType(const ADescription: string; out AType: TConvType): Boolean; overload;
function DescriptionToConvType(const AFamily: TConvFamily; const ADescription: string; out AType: TConvType): Boolean; overload;
C++
Boolean DescriptionToConvType(const AnsiString ADescription, TConvType AType);
Boolean DescriptionToConvType(const TConvFamily AFamily, const AnsiString ADescription, TConvType AType);

DescriptionToConvType returns the conversion type identifier for the conversion type (measurement unit) that was registered under the name specified by ADescription. 

AFamily is the identifier for the conversion family supplied to the RegisterConversionType function when the conversion type was registered. 

ADescription is the name supplied to the RegisterConversionType function when the conversion type was registered. Typically, it is the plural form of the measurement unit name. For example, the description for the auAcres conversion type is 'Acres'. 

AType returns the identifier for the conversion type. 

DescriptionToConvType returns true if it can successfully locate and return the specified conversion type, false otherwise.  

Delphi Examples: 

 

{
This example uses a form with a combo box, two list boxes,
an edit control, and a button.  The user selects a
conversion family from the combo box, which causes the list
boxes to fill with the conversion types registered with that
family. When the user clicks the button, a message box
appears showing the value in the edit control converted from
the units selected in the first list box to the units
selected in the second list box.
Note:   If you have not registered your own conversion families,
include the stdconvs unit in your uses clause to use the
standard conversion families.
}

{
The following OnCreate event handler for the form initializes
the combo box and list boxes:
}

procedure TForm1.FormCreate(Sender: TObject);
var
  FamilyList: TConvFamilyArray;
  i: Integer;
begin
  GetConvFamilies(FamilyList);
  for i := 0 to (Length(FamilyList) - 1) do
    ComboBox1.Items.Add(ConvFamilyToDescription(FamilyList[i]));
  ComboBox1.ItemIndex := 0; { select the first item }
  ComboBox1Select(ComboBox1); {trigger the event to initialize lists}
end;

{
The following OnClick event handler for the button reads the
value entered in the edit box and converts it between the
measurement units selected in the list boxes:
}
procedure TForm1.Button1Click(Sender: TObject);
var
  newVal: Double;
  CurFamily: TConvFamily;
  FromType, ToType: TConvType;
begin
  DescriptionToConvFamily(ComboBox1.Items[ComboBox1.ItemIndex], CurFamily);
  DescriptionToConvType(CurFamily, ListBox1.Items[ListBox1.ItemIndex], FromType);
  DescriptionToConvType(CurFamily, ListBox2.Items[ListBox2.ItemIndex], ToType);
  newVal := Convert(StrToFloat(Edit1.Text), FromType, ToType);
  ShowMessage(Format('%g %s', [newVal, ConvTypeToDescription(ToType)]));
end;

{
The following OnSelect event handler for the combo box
initializes the list boxes with the registered conversion
types for the selected family:
}
procedure TForm1.ComboBox1Select(Sender: TObject);
var
  TypeList: TConvTypeArray;
  i: Integer;
  CurFamily: TConvFamily;Description:string;
beginDescription := ComboBox1.Items[ComboBox1.ItemIndex];
  if DescriptionToConvFamily(Description, CurFamily) then
  begin
    GetConvTypes(CurFamily, TypeList);
    ListBox1.Items.Clear;
    ListBox2.Items.Clear;
    for i := 0 to Length(TypeList) -1 do
      ListBox1.Items.Add(ConvTypeToDescription(TypeList[i]));
    ListBox2.Items := ListBox1.Items;
    ListBox1.ItemIndex := 0;
    ListBox2.ItemIndex := 0;
  end;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!