Autor Beitrag
Tigu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Sa 04.03.06 20:17 
Hallo!

Ich muss in einer ListBox2 mitzählen lassen, was in der ListBox1 eingetragen wird.
Er soll jedes mal, wenn er alle Schleifen abgearbeitet hat und feststellt, dass er etwas in ListBox1 einträgt, in ListBox2 weiterzählen.
Wenn ich ihm sage, dass er eine Variable, die am Anfang auf 0 steht, nach dem Eintragen in die ListBox1 um eins erhöhen soll
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
...
begin
a:=0; 
... 
//Schleifen 
... 
if gefunden then 
a:=a+1; 
ListBox2.Items.Add(IntToStr(a)); 
end;
.....

funktioniert es nicht. Er schreibt nur beim ersten Eintrag die 1 hin, zählt aber bei den nächsten einträgen nicht weiter.

Ist bestimmt nur ein ganz doofer Denkfehler, ich komme aber nicht dahinter.
Vielleicht kann mir ja jemand einen Denkanstoß geben.
Schon mal danke für die Hilfe

Tigu


Ergenzung: Es handelt sich um einen Schalter, der Wörter in einem Suchspeil suchen lässt. Der kommplette Code des Schalters lautet wie folgt:
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:
procedure TForm1.BnSuchenClick(Sender: TObject);
var x,y,i,xrichtung,yrichtung,a:integer;
    gefunden:boolean;
    r:tgridrect;
begin
Suchwort:=uppercase(Edit1.Text);
a:=0;
for y:=1 to feld.RowCount-1 do
 for x:=feld.FixedCols to feld.ColCount -1 do
  if uppercase(feld.Cells [x,y])=Suchwort [1] then
   for yrichtung:=-1 to 1 do
 for xrichtung:=-1 to 1 do
  begin
  gefunden:=true;
  for i:=2 to length (suchwort) do
   if (x+xrichtung*(i-1)>0 ) and (x+xrichtung*(i-1)<21) and
      (y+yrichtung*(i-1)>0 ) and (y+yrichtung*(i-1)<21) then
    begin
    if uppercase(feld.Cells[x+xrichtung*(i-1),y+yrichtung*(i-1)])<>suchwort[i] then
     gefunden:=false;
    end
    else
    gefunden:=false;
     if gefunden then
      begin
      a:=a+1;
      if ListBox2.Items.IndexOF(IntToStr(a))<0 then
         ListBox2.Items.Add(IntToStr(a));
      for i:=1 to length(suchwort) do
       begin
       feld.Cells [x+xrichtung*(i-1),y+yrichtung*(i-1)]:=
             lowercase(feld.Cells[x+xrichtung*(i-1),y+yrichtung*(i-1)]);
       if ListBox1.Items.IndexOF(Suchwort)<0 then
        ListBox1.Items.Add(suchwort);
       if (((y+yrichtung*(i-1))<21) or ((y+yrichtung*(i-1))>0)) then
        begin
        if (y+yrichtung*(i-1))<21 then
         begin
         r.top:=y+yrichtung*(i-1);
         r.bottom:=y;    //senkrecht rückwärts
         end;
        if (y+yrichtung*(i-1))>0 then
         begin
         r.top:=y;        //senkrecht vorwärts
         r.bottom:=y+yrichtung*(i-1);
         end;
        r.left:=x;
        r.right:=x;
        feld.Selection:=R;
  //einzeln funktionieren die Schleifen, zusammen nicht
       if ((x+xrichtung*(i-1))>0) or ((x+xrichtung*(i-1))<21) then
        begin
        if (x+xrichtung*(i-1))>0 then
         begin
         r.left:=x+xrichtung*(i-1);       //waagerecht rückwerts
         r.right:=x+length(suchwort)-1;
         end;
        if (x+xrichtung*(i-1))<21then
         begin
         r.left:=x+xrichtung*(i-1);       //waagerecht vorwärts
         r.right:=x;
         end;
        r.top:=y;
        r.bottom:=y;
        feld.Selection:=R;
        end;
      end;
    end;
   end;
  end;
Edit1.SetFocus;
Edit1.SelectAll;
end;


Zuletzt bearbeitet von Tigu am Sa 04.03.06 20:32, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 04.03.06 20:29 
Moin!

Glaskugel hat folgendes geschrieben:
EOutOfArgs: Bitte Eingabe mit mehr Code-Details wiederholen und Anfrage erneut starten.
:wink:

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Tigu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Sa 04.03.06 20:33 
Bringt dich das weiter? (Ergänzung)
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Do 16.03.06 10:41 
Eventl. fehlt das ein Begin-End

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
if gefunden then  
begin
  a:=a+1;  
  ListBox2.Items.Add(IntToStr(a));  
end;
  
end;

_________________
Ein Nutzer der Ecke ;-)