Autor Beitrag
[vsc]PrimeTime
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20

XP SP0
Delphi 6 Pers. (eng), Delphi 2005
BeitragVerfasst: Do 30.09.04 07:56 
Hi ihr da draußen,

wie kann ich mit einem FindDialog in einer ListBox suchen.

Ich hab hier mal was Probiert, aber das tut irgendwie nicht! :(

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.BIT_searchClick(Sender: TObject);
var
  i: integer;
  gefunden: Boolean;
begin
 If FindDialog1.Execute then
   if FindDialog1.FindText<>'' then
     begin
     gefunden:=False;
     i:=-1;
     while (i<ListBox1.Items.Count-1) and not gefunden do
       begin
         Inc(i);
         if pos(FindDialog1.FindText,ListBox1.Items[i])>0 then Gefunden:=True;
         end;
         if gefunden then
           ListBox1.ItemIndex:=i
         else
           Showmessage('Nixx gefunden!');
       end;
end;


Schon mal danke im Voraus!

Greetz
PT

Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.

_________________
-=the things you own, own you=-
JESUS SAVES, the rest of you takes full damage!
smiegel
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 992
Erhaltene Danke: 1

WIN 7
D7 Prof., C#, RAD XE Prof.
BeitragVerfasst: Do 30.09.04 08:31 
Hallo,

Deine Schleife wird auch immer komplett durchlaufen. Ändere
ausblenden Delphi-Quelltext
1:
2:
3:
4:
  while (i<ListBox1.Items.Count-1) and not gefunden do  
  begin  
    ...
  end;

in
ausblenden Delphi-Quelltext
1:
2:
3:
4:
  while (i<ListBox1.Items.Count-1) or not gefunden do  // oder, nicht und!!
  begin  
    ...
  end;

dann sollte es gehen.

_________________
Gruß Smiegel
Ich weiß, daß ich nichts weiß, aber ich weiß mehr als die, die nicht wissen, daß sie nichts wissen. (Sokrates)