unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Unit2;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Button2: TButton;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Memo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure EditChange(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure EditKeyPress(Sender: TObject; var Key: Char);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
iE: Integer;
Ergebnis, Summe: String;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i1, i2: Integer;
begin
Edit2.Text:=IntToStr(random(9999));
Edit3.Text:=IntToStr(random(9999));
i1:= Length(Edit2.Text);
If i1 = 3 then Edit2.Text:= '0' + Edit2.Text;
If i1 = 2 then Edit2.Text:= '00' + Edit2.Text;
If i1 = 1 then Edit2.Text:= '000' + Edit2.Text;
i2:= Length(Edit3.Text);
If i2 = 3 then Edit3.Text:= '0' + Edit3.Text;
If i2 = 2 then Edit3.Text:= '00' + Edit3.Text;
If i2 = 1 then Edit3.Text:= '000' + Edit3.Text;
Edit4.Clear; Edit5.Clear; Edit6.Clear; Edit7.Clear; Edit8.Clear;
Ergebnis:= IntToStr(StrToInt(Edit2.Text) + StrToInt(Edit3.Text));
iE:= Length(Ergebnis);
case iE of
1: begin
Edit5.Visible:= False;
Edit6.Visible:= False;
Edit7.Visible:= False;
Edit8.Visible:= False;
//Summe:= Edit4.Text;
end;
2: begin
Edit5.Visible:= True;
Edit6.Visible:= False;
Edit7.Visible:= False;
Edit8.Visible:= False;
//Summe:= Edit4.Text + Edit5.Text;
end;
3: begin
Edit5.Visible:= True;
Edit6.Visible:= True;
Edit7.Visible:= False;
Edit8.Visible:= False;
//Summe:= Edit4.Text + Edit5.Text + Edit6.Text;
end;
4: begin
Edit5.Visible:= True;
Edit6.Visible:= True;
Edit7.Visible:= True;
Edit8.Visible:= False;
//Summe:= Edit4.Text + Edit5.Text + Edit6.Text + Edit7.Text;
end;
else begin
Edit5.Visible:= True;
Edit6.Visible:= True;
Edit7.Visible:= True;
Edit8.Visible:= True;
//Summe:= Edit4.Text + Edit5.Text + Edit6.Text + Edit7.Text + Edit8.Text;
end;
end;
Label1.Caption:= Ergebnis;
Label3.Caption:= IntToStr(iE);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
randomize;
//Form1.Show;
Button1.OnClick(self);
Button1.Enabled:= false;
Edit1.Text:= 'falsch';
memo1.Text:='1. Berechnen sie die Summe aus den gegebennen Summanden.' + #13#10 +
'2. Tragen sie ihr Ergebnis in die entsprechenden Felder ein. Es folgt eine Ausgabe, ob richtig oder falsch.' + #13#10 +
'3. Sollte ihr Ergebnis richtig sein, drücken sie auf den Button "neu" um die nächste Aufgabe zu rechnen.';
end;
procedure TForm1.EditChange(Sender: TObject);
begin
If Edit4.CanFocus and (Edit4.Text='') then Edit4.SetFocus
else If Edit5.CanFocus and (Edit5.Text='') then Edit5.SetFocus
else If Edit6.CanFocus and (Edit6.Text='') then Edit6.SetFocus
else If Edit7.CanFocus and (Edit7.Text='') then Edit7.SetFocus
else If Edit8.CanFocus and (Edit8.Text='') then Edit8.SetFocus;
case iE of
1: Summe:= Edit4.Text;
2: Summe:= Edit5.Text + Edit4.Text;
3: Summe:= Edit6.Text + Edit5.Text + Edit4.Text;
4: Summe:= Edit7.Text + Edit6.Text + Edit5.Text + Edit4.Text;
else Summe:= Edit8.Text + Edit7.Text + Edit6.Text + Edit5.Text + Edit4.Text;
end;
If Ergebnis = Summe
then begin
Button1.Enabled:= True;
Edit1.Text:= 'richtig';
end
else
begin
Button1.Enabled:= false;
Edit1.Text:= 'falsch';
end;
Label2.Caption:= Summe;
end;
// Erlaubt nur das Drücken der Ziffern-Tasten, der Kommataste und der Backspacetaste
procedure TForm1.EditKeyPress(Sender: TObject; var Key: Char);
begin
if not( (key) in ['0'..'9', #8] )
then begin
key:=#0;
end
end;
// Aboutbox
procedure TForm1.Button2Click(Sender: TObject);
begin
AboutBox.ShowModal;
end;
end.