Autor Beitrag
roKR-91
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Do 21.05.09 20:03 
hi, ich bin relativ neu hier im forum (erster beitrag).
ich soll ein einfaches würfelprogramm schreiben, bei dem der user festlegen soll wie oft gewürfelt werden soll und ob mit einem oder mit 3 würfel gewürfelt werden soll.
eigentliche dachte ich das ich dabei keine probs haben werde...irrtum, denn wir sollen zur ausgabe der werte (reale werte und prozentualer anteil) ein stringgrid verwenden...son teil hab ich allerdings noch nie verwendet...und jetz treten bei der ausgabe leider ein paar fehler auf. :(

wär nett wenn mir jmd weiterhelfen könnte

ausblenden 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:
 for i := 0 to 15 do        // feld auf 0 setzen
  wuerfel[i] := 0;

  n := Strtoint(labelededit1.Text);      //einlesen der wiederholungen

  randomize;         // ZFG starten
  for i := 1 to n do
  begin
  if radiogroup1.ItemIndex = 0 then        // ein würfel
  zahl := random(6) + 1;
    case zahl of
      1: wuerfel[0] := wuerfel[0] +1;
      2: wuerfel[1] := wuerfel[1] +1;
      3: wuerfel[2] := wuerfel[2] +1;
      4: wuerfel[3] := wuerfel[3] +1;
      5: wuerfel[4] := wuerfel[4] +1;
      6: wuerfel[5] := wuerfel[5] +1;
    end // of case
        stringgrid1.Cells[2, 2]:= inttostr(wuerfel[0])           // AUSGABE
   else
    zahl := random(15) + 3;                // 3 würfel
    case zahl of
      3: wuerfel[0] := wuerfel[0] +1;
      4: wuerfel[1] := wuerfel[1] +1;
      5: wuerfel[2] := wuerfel[2] +1;
      6: wuerfel[3] := wuerfel[3] +1;


hier die fehler:

[Fehler] Unit1.pas(19): Operator oder Semikolon fehlt
[Fehler] Unit1.pas(20): 'END' erwartet, aber 'ELSE' gefunden
[Fehler] Unit1.pas(22): Operator oder Semikolon fehlt

hab das mit der zeilenangabe nich so ganz hinbekommen...aber die zeilenangaben in den fehlern stimmen jetz ;)


Moderiert von user profile iconNarses: Topic aus Off Topic verschoben am Do 21.05.2009 um 22:53
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 21.05.09 20:31 
Hi und :welcome: im Forum!

Du hast die begin-end-Blöcke nicht oder falsch gesetzt. ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
  if radiogroup1.ItemIndex = 0 then
  begin        // ein würfel
    zahl := random(6) + 1;
    case zahl of
      1: wuerfel[0] := wuerfel[0] +1;
      2: wuerfel[1] := wuerfel[1] +1;
      3: wuerfel[2] := wuerfel[2] +1;
      4: wuerfel[3] := wuerfel[3] +1;
      5: wuerfel[4] := wuerfel[4] +1;
      6: wuerfel[5] := wuerfel[5] +1;
    end; // of case
    stringgrid1.Cells[2, 2]:= inttostr(wuerfel[0]) 
  end
  else ...

Du kannst übrigens mit [delphi(Zeilenindx)] [/delphi] die Zeilenangaben anpassen.

Grüße
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Fr 22.05.09 07:34 
Ja, dadurch, dass Du nach der if-Abfrage zu Radiogroup kein begin gesetzt hast, denkt der Interpreter, dass in dem bestimmten Fall die Zuweisung eines anderen zufälligen Wertes für die Zahl gelten soll.
Aber alles andere soll auf jeden Fall gemacht werden.
roKR-91 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  if radiogroup1.ItemIndex = 0 then        // ein würfel
  zahl := random(6) + 1;
    case zahl of
      1: wuerfel[0] := wuerfel[0] +1;
      2: wuerfel[1] := wuerfel[1] +1;
      3: wuerfel[2] := wuerfel[2] +1;
      4: wuerfel[3] := wuerfel[3] +1;
      5: wuerfel[4] := wuerfel[4] +1;
      6: wuerfel[5] := wuerfel[5] +1;
    end // of case
roKR-91 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: Fr 22.05.09 23:06 
hab jetz ma den gesamte quelltext reinkopiert...wenn ich das so mache (ab zeile 106 wirds interessant) :
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:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
 unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    LabeledEdit1: TLabeledEdit;
    Panel1: TPanel;
    RadioGroup1: TRadioGroup;
    Image2: TImage;
    Image1: TImage;
    StringGrid1: TStringGrid;
    BitBtn1: TBitBtn;
    StringGrid2: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    procedure RadioGroup1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.RadioGroup1Click(Sender: TObject);      // ausrichten der komponenten
begin
  if radiogroup1.ItemIndex = 0 then
    begin image1.visible := true;
          image2.visible := false;
          stringgrid1.Visible := true;
          stringgrid2.Visible := false;
          button2.Left := 360;
          button2.Top := 264;
          bitbtn1.Left := 512;
          bitbtn1.Top := 264;
          form1.Width := 645;
          form1.Height := 329; end
    else
    begin image1.visible := false;
          image2.visible := true; 
          stringgrid1.Visible := false;
          stringgrid2.Visible := true;
          button2.Left := 360;
          button2.Top := 264;
          bitbtn1.Left := 512;
          bitbtn1.Top := 264;
          form1.Width := 645;
          form1.Height := 329 end;
end;

procedure TForm1.Button2Click(Sender: TObject);       // RESET
begin
  Labelededit1.Text := '1';
  radiogroup1.ItemIndex := -1;
  image1.Visible := false;
  image2.Visible := false;
  stringgrid1.Visible := false;
  stringgrid2.Visible := false;
  form1.height := 411;
  form1.Width := 209;
  button2.Left := 32;
  button2.Top := 296;
  bitbtn1.Left := 32;
  bitbtn1.Top := 336;
end;

procedure TForm1.Button1Click(Sender: TObject);
var wuerfel : array [0..15] of integer;           // deklaration der variablen
    i, n, zahl : integer;
begin
  form1.Height := 470;                            //verschieben der komponenten
  button2.Top := 394;
  Button2.Left := 360;
  bitbtn1.Top := 394;
  bitbtn1.Left := 504;

  for i := 0 to 15 do        // feld auf 0 setzen
  wuerfel[i] := 0;

  n := Strtoint(labelededit1.Text);      //einlesen der wiederholungen

  randomize;
  for i := 1 to n do
  begin
  if radiogroup1.ItemIndex = 0 then        // ein würfel
  zahl := random(6) + 1;
    case zahl of
      1: wuerfel[0] := wuerfel[0] +1;
      2: wuerfel[1] := wuerfel[1] +1;
      3: wuerfel[2] := wuerfel[2] +1;
      4: wuerfel[3] := wuerfel[3] +1;
      5: wuerfel[4] := wuerfel[4] +1;
      6: wuerfel[5] := wuerfel[5] +1;
    end; // of case
        stringgrid1.Cells[2, 2]:= inttostr(wuerfel[0])           // AUSGABE
   end
   else
    zahl := random(15) + 3;                // 3 würfel
    case zahl of
      3: wuerfel[0] := wuerfel[0] +1;
      4: wuerfel[1] := wuerfel[1] +1;
      5: wuerfel[2] := wuerfel[2] +1;
      6: wuerfel[3] := wuerfel[3] +1;
      7: wuerfel[4] := wuerfel[4] +1;
      8: wuerfel[5] := wuerfel[5] +1;
      9: wuerfel[6] := wuerfel[6] +1;
      10: wuerfel[7] := wuerfel[7] +1;
      11: wuerfel[8] := wuerfel[8] +1;
      12: wuerfel[9] := wuerfel[9] +1;
      13: wuerfel[10] := wuerfel[10] +1;
      14: wuerfel[11] := wuerfel[11] +1;
      15: wuerfel[12] := wuerfel[12] +1;
      16: wuerfel[13] := wuerfel[13] +1;
      17: wuerfel[14] := wuerfel[14] +1;
      18: wuerfel[15] := wuerfel[15] +1;   
    end; // of case
  end;


end.



kommen folgende fehlermeldungen :

[Warnung] Unit1.pas(99): Variable 'zahl' ist möglicherweise nicht initialisiert worden
[Fehler] Unit1.pas(109): 'END' erwartet, aber 'ELSE' gefunden
[Fehler] Unit1.pas(111): ';' erwartet, aber 'CASE' gefunden
[Fehler] Unit1.pas(128): '.' erwartet, aber ';' gefunden
Bergmann89
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1742
Erhaltene Danke: 72

Win7 x64, Ubuntu 11.10
Delphi 7 Personal, Lazarus/FPC 2.2.4, C, C++, C# (Visual Studio 2010), PHP, Java (Netbeans, Eclipse)
BeitragVerfasst: Fr 22.05.09 23:18 
HI,

du hast das begin nach deiner if-Anweisung vergessen (Zeile 97)
das sollte eig alle 3 Fehler auf einma beheben...

MfG Bergmann.

_________________
Ich weiß nicht viel, lern aber dafür umso schneller^^
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Sa 23.05.09 11:29 
user profile iconroKR-91 hat folgendes geschrieben Zum zitierten Posting springen:
hab jetz ma den gesamte quelltext reinkopiert...wenn ich das so mache (ab zeile 106 wirds interessant) :

Ich habe dir doch bereits hier geschrieben, was du falsch gemacht hast und wie du die Zeilenangaben anpasssen kannst. :roll:
ausblenden Delphi-Quelltext
 
96:
97:
98:
{ ... }
begin
...
end;
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Sa 23.05.09 11:43 
Also hier Dein berichtigter Quelltext:
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:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
 unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    LabeledEdit1: TLabeledEdit;
    Panel1: TPanel;
    RadioGroup1: TRadioGroup;
    Image2: TImage;
    Image1: TImage;
    StringGrid1: TStringGrid;
    BitBtn1: TBitBtn;
    StringGrid2: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    procedure RadioGroup1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.RadioGroup1Click(Sender: TObject);      // ausrichten der komponenten
begin
  if radiogroup1.ItemIndex = 0 then
    begin image1.visible := true;
          image2.visible := false;
          stringgrid1.Visible := true;
          stringgrid2.Visible := false;
          button2.Left := 360;
          button2.Top := 264;
          bitbtn1.Left := 512;
          bitbtn1.Top := 264;
          form1.Width := 645;
          form1.Height := 329; end
    else
    begin image1.visible := false;
          image2.visible := true; 
          stringgrid1.Visible := false;
          stringgrid2.Visible := true;
          button2.Left := 360;
          button2.Top := 264;
          bitbtn1.Left := 512;
          bitbtn1.Top := 264;
          form1.Width := 645;
          form1.Height := 329 end;
end;

procedure TForm1.Button2Click(Sender: TObject);       // RESET
begin
  Labelededit1.Text := '1';
  radiogroup1.ItemIndex := -1;
  image1.Visible := false;
  image2.Visible := false;
  stringgrid1.Visible := false;
  stringgrid2.Visible := false;
  form1.height := 411;
  form1.Width := 209;
  button2.Left := 32;
  button2.Top := 296;
  bitbtn1.Left := 32;
  bitbtn1.Top := 336;
end;

procedure TForm1.Button1Click(Sender: TObject);
var wuerfel : array [0..15] of integer;           // deklaration der variablen
    i, n, zahl : integer;
begin
  form1.Height := 470;                            //verschieben der komponenten
  button2.Top := 394;
  Button2.Left := 360;
  bitbtn1.Top := 394;
  bitbtn1.Left := 504;

  for i := 0 to 15 do        // feld auf 0 setzen
  wuerfel[i] := 0;

  n := Strtoint(labelededit1.Text);      //einlesen der wiederholungen

  randomize;
  for i := 1 to n do
  begin
  if radiogroup1.ItemIndex = 0 then        // ein würfel
  zahl := random(6) + 1;
    case zahl of
      1: wuerfel[0] := wuerfel[0] +1;
      2: wuerfel[1] := wuerfel[1] +1;
      3: wuerfel[2] := wuerfel[2] +1;
      4: wuerfel[3] := wuerfel[3] +1;
      5: wuerfel[4] := wuerfel[4] +1;
      6: wuerfel[5] := wuerfel[5] +1;
    end; // of case
        stringgrid1.Cells[2, 2]:= inttostr(wuerfel[0])           // AUSGABE
   end
   else
    begin // des else-Zweiges <- Dieses fehlte!!!!
    zahl := random(15) + 3;                // 3 würfel
    case zahl of
      3: wuerfel[0] := wuerfel[0] +1;
      4: wuerfel[1] := wuerfel[1] +1;
      5: wuerfel[2] := wuerfel[2] +1;
      6: wuerfel[3] := wuerfel[3] +1;
      7: wuerfel[4] := wuerfel[4] +1;
      8: wuerfel[5] := wuerfel[5] +1;
      9: wuerfel[6] := wuerfel[6] +1;
      10: wuerfel[7] := wuerfel[7] +1;
      11: wuerfel[8] := wuerfel[8] +1;
      12: wuerfel[9] := wuerfel[9] +1;
      13: wuerfel[10] := wuerfel[10] +1;
      14: wuerfel[11] := wuerfel[11] +1;
      15: wuerfel[12] := wuerfel[12] +1;
      16: wuerfel[13] := wuerfel[13] +1;
      17: wuerfel[14] := wuerfel[14] +1;
      18: wuerfel[15] := wuerfel[15] +1;   
    end; // of case
    end; // des else-Zweiges <- Dieses fehlte!!!!
  end;


end.


Markiert habe ich die beiden hinzugefügten Zeilen mit "<- Dieses fehlte!!!!"
Sonst macht er ja nur die eine Zeile im else-Fall und die anderen in jedem Fall.

(Das ist ja leider nicht genauso wie bei: try..except..end;
auch wenn es da auch sauberer wäre, die Teile in begin und end einzuklammern)
roKR-91 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 22



BeitragVerfasst: So 24.05.09 14:56 
user profile iconBergmann89 hat folgendes geschrieben Zum zitierten Posting springen:
HI,

du hast das begin nach deiner if-Anweisung vergessen (Zeile 97)
das sollte eig alle 3 Fehler auf einma beheben...

MfG Bergmann.


thx daran lags :flehan:

nun zur nächsten frage :P
wie kann ich in die fixed zellen in dem stringrid etwas hineinschreiben ???
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: So 24.05.09 16:00 
Das geht einfach nur so, indem Du die Zeile (=Row), bzw. Spalte (=Col) gleich 0 (=Null) setzt.
Ich habe hier jetzt mal was als Beispiel reingeschreiben, was wirklich JEDE Zelle beschriftet (Wobei nachher mein Hallo auch nicht mehr da steht!):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.FormCreate(Sender: TObject);
var Spalte,Zeile:integer;
begin
//So kannst Du einen einzelnen Eintrag machen:
StringGrid1.Cells[0,0]:='Hallo';
for Spalte:=0 to StringGrid1.ColCount do
        begin
        for Zeile:=0 to StringGrid1.RowCount do
                begin
                StringGrid1.Cells[Spalte,Zeile]:='Spalte:'+IntToStr(Spalte)+'Zeile:'+IntToStr(Zeile);
                end;
        end;
end;
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: So 24.05.09 16:22 
Übrigens:Ich weiß leider nicht, ob wir Dich schon darauf hingewisen haben (u.a., da mir mein Kurzzeitgedächtnis fehlt):
Du brauchst doch nicht das ganze mit Case of machen - also nicht so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
  if radiogroup1.ItemIndex = 0 then        // ein würfel
    begin
    zahl := random(6) + 1;
    case zahl of
      1: wuerfel[0] := wuerfel[0] +1;
      2: wuerfel[1] := wuerfel[1] +1;
      3: wuerfel[2] := wuerfel[2] +1;
      4: wuerfel[3] := wuerfel[3] +1;
      5: wuerfel[4] := wuerfel[4] +1;
      6: wuerfel[5] := wuerfel[5] +1;
    end // of case
    end; //Der IF-Abfrage

Sondern es würde in diesem Fall doch auch schon so vollkommen reichen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  if radiogroup1.ItemIndex = 0 then        // ein würfel
    begin
    zahl := random(6) + 1;
    wuerfel[zahl-1] := wuerfel[zahl-1] +1;
    end; //Der IF-Abfrage
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Mo 25.05.09 09:44 
Hi, falls es dich interessiert erlär ich dir mal das mit dem Fehler ^^ dann passiert dir das nicht mehr.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
if .. then
  case zahl of
    1 ...
    2 ...
  end;
else
...


dann hätte es funktioniert solange zischen "if then" und "else" 1 Anweisung steht brauchst du kein "begin / end" wenn es mehr sind musst du es entsprechend setzen.
Aber wenn kein begin da ist auch kein end setzen ;)
ffgorcky
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 573

WIN XP/2000 & 7Prof (Familie:Win95,Win98)

BeitragVerfasst: Mi 27.05.09 15:56 
Also thepaine91 - da stehen bei Dir doch jetzt mehrere Anweisungen zwischen if und else...
Nähmlich diese hier alle:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
  case zahl of
    1: ...
    2: ...
  end; // der Case-Anweisung

aber es steht nur eine Anweisung (Nämlich die von case of bis end; // der Case-Anweisung) auf der direkten Stufe darunter!
Dadurch ist das schon richtig, dass begin und end; weggelassen werden können.
Aber hauptsache, er kommt dadurch nicht auf falsche Gedanken - und vergisst dann bei einer Quelltext-Erweiterung in diesem Bereich das begin und end;.

...wobei Dein Quelltext ja so gar nicht funktionieren kann weil direkt vor einem else kein ; erlaubt ist!
thepaine91
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 763
Erhaltene Danke: 27

Win XP, Windows 7, (Linux)
D6, D2010, C#, PHP, Java(Android), HTML/Js
BeitragVerfasst: Do 28.05.09 08:09 
tja vorführeffekt ^^ hast wohl recht und es ist in dem Fall auf der Ebene eine Anweisung also stimmt ja was ich sage :-) hab das nur bissel zu schnell verfasst dann passiert mal so ein flüchtigkeits Fehler.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 28.05.09 08:59 
user profile iconffgorcky hat folgendes geschrieben Zum zitierten Posting springen:
Sondern es würde in diesem Fall doch auch schon so vollkommen reichen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  if radiogroup1.ItemIndex = 0 then        // ein würfel
    begin
    zahl := random(6) + 1;
    wuerfel[zahl-1] := wuerfel[zahl-1] +1;
    end; //Der IF-Abfrage


Geht noch kürzer. Dazu zu erst das Offensichtliche: Aufhebung der Addition + 1, denn warum eine Operation ausführen, die man gleich im Anschluss (mehrfach) rückgängig machen muss?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  if radiogroup1.ItemIndex = 0 then        // ein würfel
  begin
    zahl := random(6);
    wuerfel[zahl] := wuerfel[zahl] +1;
  end; //Der IF-Abfrage


Und für das Addieren des Wertes 1 gibt es die Prozedur Inc (Inkrement):
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
  if radiogroup1.ItemIndex = 0 then        // ein würfel
  begin
    zahl := random(6);
    Inc(wuerfel[zahl]);
  end; //Der IF-Abfrage


Und siehe da: Kürzer UND schneller geworden!

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.