Autor Beitrag
.50AE
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 100



BeitragVerfasst: Mi 05.04.06 13:55 
Hallo!
Ich Programmiere gerade einen Vokabeltrainer und habe folgendes Problem wenn die nächste Vokabel berechnet werden soll:
Da wo FEEEEEEEHHHLER!!!! steht kommt folgende Meldung: "Declaration expected but IF found."

Ich hab extra schon alle "begin"'s und "end"'s nachgezählt aber die stimmen überein...
Woran liegt das bloß?

Wenn ich nur irgendwas übersehen hab; sry ...

MfG
.50AE


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:
//nächste vokabel berechnen
procedure next_vocab;
begin
form_mainform.etrans.Text := '';
form_mainform.etrans.Enabled := true;
nextvoc := false;
//Wenn noch nicht alle abgefragt, DANN ... sonst ...
if (countasked < form_mainform.listtemp1.Items.Count) then begin
        //Nächste Vokabel berechnen und prüfen ob sie schon dran kam
          if (voctraining = 1) then
                begin
                randomize;
                currentvoc := random(form_mainform.listtemp1.Items.Count);
                     while vocused[currentvoc] = true do
                     currentvoc := random(form_mainform.listtemp1.Items.Count);
                     end;
                form_mainform.lvoc.Caption := form_mainform.listtemp1.Items.Strings[currentvoc];
                end;
          if (voctraining = 2) then
                begin
                  if (countasked < form_mainform.listtemp1.Items.Count) then
                    currentvoc := currentvoc + 1;
                form_mainform.lvoc.Caption := form_mainform.listtemp1.Items.Strings[currentvoc];
                end;
          if (voctraining = 3) then
                begin
                randomize;
                currentvoc := random(form_mainform.listtemp2.Items.Count);
                     while vocused[currentvoc] = true do
                     currentvoc := random(form_mainform.listtemp2.Items.Count);
                     end;
                form_mainform.lvoc.Caption := form_mainform.listtemp2.Items.Strings[currentvoc];
                end;
          if (voctraining = 4) then //FEEEEEEEHHHLER!!!!
                begin
                  if (countasked < form_mainform.listtemp1.Items.Count) then
                    currentvoc := currentvoc + 1;
                form_mainform.lvoc.Caption := form_mainform.listtemp2.Items.Strings[currentvoc];
                end;
          vocused[currentvoc] := true;
          countasked := countasked + 1;
          form_mainform.lwordof.Caption := 'Wort '+inttostr(countasked)+' von '+inttostr(form_mainform.listtemp1.Items.Count);
        //Wenn noch nicht alle abgefragt, dann ... SONST ...
end else showmessage('Alle Vocs durch!');
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: Mi 05.04.06 14:19 
Beim while in Zeile 29 hast du kein begin, deshalb ist end in Zeile 31 überflüssig

_________________
Markus Kinzler.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 05.04.06 14:19 
Du hast alle nachgezählt??? :rofl: (Sorry, ich konnte nicht anders, ist nicht böse gemeint)
Und was ist mit den end's in den Zeilen 16 und 31? Dazu gibt es doch gar kein begin!

Erklärung: while hat genau wie if kein "eingebautes" begin, braucht also auch nur ein end, wenn man es nach der while-Bedingung mit begin anfängt!
Das war dir vermutlich nicht klar.

//EDIT: Langsamer, aber ausführlicher... :P
raiguen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 374

WIN 2000prof, WIN XP prof
D7EP, MSSQL, ABSDB
BeitragVerfasst: Mi 05.04.06 14:41 
Moin :-)
user profile iconmkinzler hat folgendes geschrieben:
Beim while in Zeile 29 hast du kein begin, deshalb ist end in Zeile 31 überflüssig

Der Vollständigkeit halber: Zeile 16 ist dementsprechend auch mehr als flüssig-> nämlich überflüssig! ;-)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 05.04.06 14:47 
user profile iconraiguen hat folgendes geschrieben:
Moin :-)
user profile iconmkinzler hat folgendes geschrieben:
Beim while in Zeile 29 hast du kein begin, deshalb ist end in Zeile 31 überflüssig

Der Vollständigkeit halber: Zeile 16 ist dementsprechend auch mehr als flüssig-> nämlich überflüssig! ;-)

:roll: Hab ich doch schon vor 20 Minuten gleichzeitig mit user profile iconmkinzler's Post geschrieben...
.50AE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 100



BeitragVerfasst: Mi 05.04.06 14:47 
Oh ja; ich hab zwar schon while Schleifen eingesetzt aber hier nicht mehr dran gedacht, dass man da ein begin braucht.

Thx @all; ich war am verzweifeln -.-

.50ae
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 05.04.06 14:50 
Brauchst du ja gar nicht, wenn du nur einen Befehl hast. Begin und end als Paar brauchst du grundsätzlich nur, wenn dazwischen mehr als ein Befehl steht (abgesehen von dem Prozeduranfang und -ende bzw. dem Programmanfang und -ende natürlich)!
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mi 05.04.06 14:56 
Zur Sicherheit würde ich aber immer Begin und end verwenden. Wie schnell fügt man irgendwo was ein und sucht das ewig!

_________________
Markus Kinzler.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mi 05.04.06 15:11 
Das ist mir zwar noch nie passiert, aber wer's braucht...
Falsch ist es ja nicht.

Ich finde aber, dass Quelltext übersichtlicher ist, wenn man begin..end nur da benuzt, wo es notwendig ist.