home *** CD-ROM | disk | FTP | other *** search
- unit conv;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls,
- convutils,stdconvs;
-
- type
- TForm1 = class(TForm)
- ListBox1: TListBox;
- ListBox2: TListBox;
- Edit1: TEdit;
- Button1: TButton;
- ComboBox1: TComboBox;
- msglabel: TLabel;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- ResultEdit: TEdit;
- Label5: TLabel;
- procedure FormCreate(Sender: TObject);
- procedure ComboBox1Select(Sender: TObject);
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- procedure ShowMsg( msg : string );
- procedure ShowResult(fromval,toval : Double; FromType,ToType :TConvType);
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.dfm}
-
- procedure TForm1.ShowMsg( msg : string );
- begin
- msglabel.Caption := msg;
- end;
-
- procedure TForm1.ShowResult(fromval,toval : Double; FromType,ToType :TConvType);
- begin
- ResultEdit.Text := Format('%g %s = %g %s',
- [fromval,ConvTypeToDescription(FromType),
- toval,ConvTypeToDescription(ToType)]);
- end;
-
- 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;
-
- procedure TForm1.ComboBox1Select(Sender: TObject);
- var
- TypeList: TConvTypeArray;
- i: Integer;
- CurFamily:TConvFamily;
- Description: string;
- begin
- Description := ComboBox1.Items[ComboBox1.ItemIndex];
- if DescriptionToConvFamily(Description, CurFamily) then
- begin
- GetConvTypes(CurFamily, TypeList);
- ListBox1.Items.Clear; // we've added this
- 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;
-
- procedure TForm1.Button1Click(Sender: TObject);
- var
- dblval,newval: Double;
- CurFamily: TConvFamily;
- FromType, ToType: TConvType;
- begin
- ShowMsg('');
- dblval := StrToFloatDef(Edit1.Text, 0.0);
- if dblval = 0.0 then
- ShowMsg('Enter a meaningful integer or floating point value.' )
- else
- begin
- DescriptionToConvFamily(ComboBox1.Items[ComboBox1.ItemIndex], CurFamily);
- DescriptionToConvType(CurFamily, ListBox1.Items[ListBox1.ItemIndex], FromType);
- DescriptionToConvType(CurFamily, ListBox2.Items[ListBox2.ItemIndex], ToType);
- // the following is incorrect in the Help file example
- // newVal := Convert(FromType, ToType, StrToFloat(Edit1.Text));
- newVal := Convert(dblVal, FromType, ToType );
- // we've added our own result display
- // ShowMessage(Format('%g %s', [newVal, ConvTypeToDescription(ToType)]));
- ShowResult(dblval,newval,FromType,ToType);
- end;
- end;
-
- end.
-