unit Unit1 interface uses Windows Messages SysUtils Variants Classes G

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
ProgressBar1: TProgressBar;
ProgressBar2: TProgressBar;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
x0,x1,i,temp:integer;
f:real;
begin
x0:=1;
x1:=1;
temp:=0;
f:=0;
Randomize;
for i:=0 to 1000 do
begin
temp:=Random(2);
if temp=1 then
begin
x1:=x1+1;
Label2.Caption:=('1 ==> ' + inttostr(x1));
end
else
begin
x0:=x0+1;
Label1.Caption:='0 ==> '+ inttostr(x0);
end;
f:=x0/x1;
Label3.Caption:='ratio (0/1) ==> '+ floattostr(f);
ProgressBar1.Position:=x0;
end;
end;
end.