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
Pigrecatore - 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;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     LabelRisultato: TLabel;
  17.     LabeledEditErrore: TLabeledEdit;
  18.     procedure FormCreate(Sender: TObject);
  19.     procedure LabeledEditErroreChange(Sender: TObject);
  20.   private
  21.     { private declarations }
  22.     procedure cancella;
  23.   public
  24.     { public declarations }
  25.   end;
  26.  
  27. var
  28.   Form1: TForm1;
  29.  
  30. implementation
  31.  
  32. function termine(n:qword):double;
  33. var segno:double;
  34. begin
  35.   if (n and 1)=1 then
  36.   begin
  37.     segno:=0.0-1.0
  38.   end
  39.   else
  40.   begin
  41.     segno:=1.0;
  42.   end;
  43.   termine:=segno*(1.0/(2.0*n+1.0));
  44. end;
  45.  
  46. {$R *.lfm}
  47.  
  48. { TForm1 }
  49.  
  50. procedure TForm1.FormCreate(Sender: TObject);
  51. begin
  52.   Form1.Caption:='Pigrecatore';
  53.   cancella;
  54. end;
  55.  
  56. function valorizza(numero:string; var x:double):boolean;
  57. var errore:integer;
  58. begin
  59.   val(numero, x, errore);
  60.   valorizza:=errore=0;
  61. end;
  62.  
  63. procedure TForm1.LabeledEditErroreChange(Sender: TObject);
  64. var t,somma,epsilon:double;
  65.     i:qword;
  66. begin
  67.   if valorizza(LabeledEditErrore.Text, epsilon) then
  68.   begin
  69.     LabelRisultato.Caption:='';
  70.     i:=0;
  71.     t:=termine(i);
  72.     somma:=t;
  73.     while (abs(t)>=abs(epsilon)) and (i<20000000) do
  74.     begin
  75.       i:=i+1;
  76.       t:=termine(i);
  77.       somma:=somma+t;
  78.     end;
  79.     LabelRisultato.Caption:=Format('P_greco: %16.14f',[somma*4]);
  80.   end
  81.   else
  82.     LabelRisultato.caption:='Sono ammessi soltanto valori numerici';
  83. end;
  84.  
  85. procedure TForm1.cancella;
  86. begin
  87.   LabeledEditErrore.text:='';
  88.   LabelRisultato.Caption:='';
  89. end;
  90.  
  91. end.