Autor Beitrag
GrimReaper
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Di 23.05.06 19:29 
Habe ein kleines Programm geschrieben um das große 1*1, mit gegebenen zufallszahlen zu üben
funktioniert auch
mit dem ersten button bekommt man zwei zufallszahlen, dann soll man sein ergebnis eingeben und mit einem weiteren button überprüfen können ob das ergebnis stimmt (je nachdem ob es stimmt oder nicht wird ein label sichtbar, dass einem zeigt ob es stimmt oder nciht)

jedoch stimmt da was nicht, den zweiten button zum berechnen braucht man garnicht zu drücken da das ergebnis gleich überprüft wird.


Findet einer den Fehler?
ausblenden volle Höhe Delphi-Quelltext
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:
63:
64:
65:
66:
67:
68:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    RechnenFeld: TEdit;
    Zufallszahl: TBitBtn;
    Neuezahlen: TBitBtn;
    Berechnen: TBitBtn;
    Schliessen: TBitBtn;
    Bewertung: TLabel;
    Einfuehrung: TLabel;
    Einfuehrung2: TLabel;
    RechnenFeld2: TEdit;
    RechnenFeld3: TEdit;
    MalZeichen: TLabel;
    GleichheitsZeichen: TLabel;
    Bewertung2: TLabel;
    procedure ZufallszahlClick(Sender: TObject);
    procedure NeuezahlenClick(Sender: TObject);
    procedure RechnenFeld3Change(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1; zahl1 , zahl2, zahl3, zahl4: integer; xzahl , x2zahl: string;

implementation

{$R *.dfm}

procedure TForm1.ZufallszahlClick(Sender: TObject);
begin
Randomize;
zahl1 := Random(99);
xzahl := FloatToStr (zahl1);
RechnenFeld.Text := xzahl;
Randomize;
zahl2 := Random(99);
x2zahl := FloatToStr (zahl2);
RechnenFeld2.Text := x2zahl;
end;

  procedure TForm1.NeuezahlenClick(Sender: TObject);
  begin
  RechnenFeld.Text  := '';
  RechnenFeld2.Text := '';
  RechnenFeld3.text := '';
  Bewertung.visible := false;
  Bewertung2.visible := false;
  end;

procedure TForm1.RechnenFeld3Change(Sender: TObject);
begin
zahl3 := StrToInt (RechnenFeld3.text);
zahl4 := zahl1*zahl2;
if zahl3=zahl4 then bewertung.visible := true else bewertung2.visible := true;
end;

 end.
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 23.05.06 19:37 
Dem Namen der Eventhandlet-Prozedur nach, wird die Überprüfung nicht bei Bestätigen des Buttons, sondern beim Ändern des Inhalts des Editfelds durchgeführt.

_________________
Markus Kinzler.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Di 23.05.06 19:37 
Der Fehler liegt darin, dass du im OnChange von Feld3 schon die ganzen Prüfungen machst, statt im OnClick des Auswertungs-Button.

Tipp:
- Randomize ist nur einmal erforderlich. Am besten im FormCreate.
GrimReaper Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Di 23.05.06 19:44 
ok jetzt geht's

aber die labels werden nicht angezeigt
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 23.05.06 20:01 
Füge noch ein
ausblenden Delphi-Quelltext
1:
TForm1.Update;					

ein.

_________________
Markus Kinzler.
GrimReaper Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Di 23.05.06 20:05 
wo den genau? ^^'
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 23.05.06 20:09 
Am Ende der Prozedur TForm1.RechnenFeld3Change.

_________________
Markus Kinzler.
GrimReaper Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Di 23.05.06 20:13 
hm... da bekomme ich dann eine fehlermeldung
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 23.05.06 20:24 
Welche?

[Edit: Muß natürlich Form1.Update; heißen}

_________________
Markus Kinzler.
GrimReaper Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Di 23.05.06 20:31 
[Error] Unit1.pas(66): Unknown directive: 'TForm1'
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Di 23.05.06 20:32 
Korrigier mal TForm1.Update;in Form1.Update; oder Update;

_________________
Markus Kinzler.
GrimReaper Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Di 23.05.06 20:37 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.RechnenFeld3Change(Sender: TObject);   
begin   
zahl3 := StrToInt (RechnenFeld3.text);   
zahl4 := zahl1*zahl2;   
if zahl3=zahl4 then bewertung.visible := true else bewertung2.visible := true;   
update;
end;


so hab ich's nun
es kommt keine fehlermeldung aber es kommen trotzdem keine labels
Moderiert von user profile iconjasocul: Delphi-Tags eingefügt