home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 December / DPPCPRO1202.ISO / Editorial / ConvertIt.dpr next >
Encoding:
Text File  |  2002-08-26  |  1.8 KB  |  63 lines

  1. program ConvertIt;
  2.  
  3. uses System.Windows.Forms;
  4.  
  5. type
  6.     ConvertForm = class (Form)
  7.     private
  8.         ResultList: ListBox;
  9.         CelsiusEdit: NumericUpDown;
  10.     public
  11.         constructor Create;
  12.         procedure Convert (Sender: TObject; Args: EventArgs);
  13.     end;
  14.  
  15. function CelsiusToFahrenheit (AValue: Double): Double;
  16. begin
  17.     Result := ((AValue * 9) / 5) + 32;
  18. end;
  19.  
  20. procedure ConvertForm.Convert (Sender: TObject; Args: EventArgs);
  21. var
  22.     LCelsius: Double;
  23. begin
  24.     LCelsius := System.Convert.ToDouble (CelsiusEdit.Value);
  25.     with ResultList do begin
  26.         BeginUpdate;
  27.         Items.Clear;
  28.         Items.Add (System.Convert.ToString ('Celsius = '    + System.Convert.ToString (LCelsius)));
  29.         Items.Add(System.Convert.ToString  ('Fahrenheit = ' + System.Convert.ToString (CelsiusToFahrenheit (LCelsius))));
  30.         Items.Add (System.Convert.ToString ('Kelvin = '     + System.Convert.ToString (LCelsius + 273.15)));
  31.         EndUpdate;
  32.     end;
  33. end;
  34.  
  35. constructor ConvertForm.Create;
  36. begin
  37.     Inherited Create;
  38.     Width := 240;  Height := 320;
  39.     CelsiusEdit := NumericUpDown.Create;
  40.     with CelsiusEdit do begin
  41.         Left := 8;  Top := 8;  Width := 217;  
  42.     Value := System.Convert.ToDecimal (100.0);
  43.         Maximum := System.Convert.ToDecimal(10000.0);
  44.         Minimum := System.Convert.ToDecimal(-1000.0);
  45.         Add_ValueChanged (EventHandler.Create (Self, NativeInt (@ConvertForm.Convert)));
  46.     end;
  47.  
  48.     ResultList := ListBox.Create;
  49.     with ResultList do begin
  50.         Left := 8;  Top := 40;  Width := 217;  Height := 217;
  51.     end;
  52.  
  53.     Text := 'Temp Converter';
  54.     Controls.Add (CelsiusEdit);
  55.     Controls.Add (ResultList);
  56.     StartPosition := FormStartPosition.CenterScreen;
  57.     Convert (Nil, Nil);
  58. end;
  59.  
  60. begin
  61.     Application.Run (ConvertForm.Create);
  62. end.
  63.