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
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| ... begin a:=0; ... ... 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:
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; end; if (y+yrichtung*(i-1))>0 then begin r.top:=y; r.bottom:=y+yrichtung*(i-1); end; r.left:=x; r.right:=x; feld.Selection:=R; 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); r.right:=x+length(suchwort)-1; end; if (x+xrichtung*(i-1))<21then begin r.left:=x+xrichtung*(i-1); r.right:=x; end; r.top:=y; r.bottom:=y; feld.Selection:=R; end; end; end; end; end; Edit1.SetFocus; Edit1.SelectAll; end; |