unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Gauges;
type
TForm1 =
class(TForm)
Label1: TLabel;
Label2: TLabel;
Edit1: TEdit;
Button1: TButton;
Gauge1: TGauge;
Label3: TLabel;
Label4: TLabel;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
zahl1, zahl2, zahl3, ergebnis, antwort : real;
ok, r :integer;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
Randomize;
zahl1:=Random(10);
zahl2:=Random(10);
zahl3:=Random(10);
if zahl1=0
then FormShow(Sender);
if zahl2=0
then FormShow(Sender);
if zahl3=0
then FormShow(Sender);
Label1.Caption:=FloatToStr(zahl1) + '
= ' + FloatToStr(zahl2) + '
x' + '
- ' +FloatToStr(zahl3);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
antwort:=StrToFloat(Edit1.Text);
ergebnis:=(zahl1 + zahl3) / zahl2;
ergebnis:=round(ergebnis*10)/10;
Label3.Caption:=FloatToStr(ergebnis);
if
antwort=ergebnis
then
begin
ShowMessage('
Richtig !!!');
ok:=ok+1;
r:=r+1;
Gauge1.Progress:=r;
end
else
begin
ShowMessage('
False');
r:=r+1;
Gauge1.Progress:=r;
end;
FormShow(Sender);
Edit1.Text:='
';
Edit1.SetFocus;
if
Gauge1.Progress=100
then
Label4.Caption:='
Sie haben ' + IntToStr(ok) + '
von ' + IntToStr(r);
end;
procedure TForm1.FormKeyDown(Sender: TObject;
var Key: Word;
Shift: TShiftState);
begin
if shift=[]
then begin
case key
of
27: Close;
13: Button1Click(Sender);
end;
end;
end;
end.