Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Kelvin - gestoredelform.pas

gestoredelform.pas

Caricato da: Poggi Marco
Scarica il programma completo

  1. unit GestoreDelForm;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  9.   StdCtrls,Temperature,LeggiNumeri;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     LabelUnita: TLabel;
  17.     LabelRisultato: TLabel;
  18.     LabeledEditIngresso: TLabeledEdit;
  19.     RadioButtonCelsius: TRadioButton;
  20.     RadioButtonKelvin: TRadioButton;
  21.     RadioGroupConversione: TRadioGroup;
  22.     procedure FormCreate(Sender: TObject);
  23.     procedure LabeledEditIngressoChange(Sender: TObject);
  24.     procedure LabeledEditIngressoKeyPress(Sender: TObject; var Key: char);
  25.     procedure RadioButtonKelvinChange(Sender: TObject);
  26.   private
  27.     { private declarations }
  28.     procedure stampaRisultato(temperatura:double);
  29.     procedure focalizza;
  30.     var attivo:boolean;
  31.   public
  32.     { public declarations }
  33.   end;
  34.  
  35. var
  36.   Form1: TForm1;
  37.   g:gradi;
  38.  
  39. implementation
  40.  
  41. {$R *.lfm}
  42.  
  43. { TForm1 }
  44.  
  45. procedure TForm1.FormCreate(Sender: TObject);
  46. begin
  47.   attivo:=false;
  48.   g:=gradi.crea;
  49.   Form1.Caption:='Kelvin';
  50.   LabeledEditIngresso.EditLabel.Caption:='Temperatura';
  51.   LabeledEditIngresso.Caption:='';
  52.   RadioGroupConversione.Caption:='Converti in';
  53.   RadioButtonCelsius.Caption:='Celsius';
  54.   RadioButtonKelvin.Caption:='Kelvin';
  55.   LabelUnita.Caption:='°C';
  56.   RadioButtonKelvin.Checked:=true;
  57.   LabelRisultato.Caption:='';
  58.   LabeledEditIngresso.ReadOnly:=true;
  59.   LabelUnita.Caption:='°C';
  60. end;
  61.  
  62. procedure TForm1.LabeledEditIngressoChange(Sender: TObject);
  63. begin
  64.   stampaRisultato(StrToFloatDef(LabeledEditIngresso.Caption, 0.0));
  65. end;
  66.  
  67. procedure TForm1.LabeledEditIngressoKeyPress(Sender: TObject; var Key: char);
  68. begin
  69.   LabeledEditIngresso.Caption:=tasto(LabeledEditIngresso.Caption, Key);
  70. end;
  71.  
  72. procedure TForm1.stampaRisultato(temperatura:double);
  73. begin
  74.  if RadioButtonCelsius.Checked then
  75.   begin
  76.      LabelRisultato.Caption:=g.aCelsius(temperatura);
  77.      LabelUnita.Caption:='K';
  78.   end
  79.   else
  80.   begin
  81.     LabelRisultato.Caption:=g.aKelvin(temperatura);
  82.     LabelUnita.Caption:='°C';
  83.   end;
  84.   focalizza;
  85. end;
  86.  
  87. procedure TForm1.RadioButtonKelvinChange(Sender: TObject);
  88. begin
  89.   stampaRisultato(StrToFloatDef(LabeledEditIngresso.Caption, 0.0));
  90. end;
  91.  
  92. procedure TForm1.focalizza;
  93. begin
  94.  if attivo then
  95.  begin
  96.   LabeledEditIngresso.SetFocus;
  97.   LabeledEditIngresso.SelStart:=length(LabeledEditIngresso.Caption);
  98.   LabeledEditIngresso.SelLength:=0;
  99.  end
  100.  else attivo:=true;
  101. end;
  102.  
  103. end.