Autor Beitrag
Michael78
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20

WIN XP
D7 Prof
BeitragVerfasst: Sa 02.10.04 00:37 
Hallo ihr Programmierer dieser Welt!!!!

Hab folgendes Problem!

Hab ne Listbox erstellt, in welcher ich speichern und suchen kann.

So nun zum Problem:

Das Programm soll wenn es einen Eintrag gefunden hat auch diesen gleich in der Listbox markieren!
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:
procedure TForm1.EdtneuerFilmKeyDown(Sender: TObject;var Key: Word;
  Shift: TShiftState);
var
gefunden:Boolean;
i:Integer;
begin
if key= VK_Return
    then
        begin
        gefunden:=False;
        for i:=0 to Listbox1.Items.Count-1 do
            begin
            if EdtneuerFilm.Text=Listbox1.Items[i]
                then
                    begin
                    showmessage('Film schon in der Liste vorhanden');
                    gefunden:=True;
                    end;
             end;
         begin
         if gefunden=False
            then
                begin
                Listbox1.Items.add(EdtneuerFilm.Text);
                EdtneuerFilm.Clear;
                EdtneuerFilm.SetFocus;
                end;
          end;
          end;

end;


Hoffe ihr wisst was ich meine!!!!!!!!


Zuletzt bearbeitet von Michael78 am Sa 02.10.04 01:50, insgesamt 1-mal bearbeitet
Jörg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 71

Win 2000, Win XP
Delphi 1, 3, 5, 7
BeitragVerfasst: Sa 02.10.04 00:57 
Bitte editiere Deinen Beitrag: Code-Tags hinzufügen und Quelltext einrücken! Kann ja kein Schw... lesen, deshalb mach ich mir auch nicht die Mühe, nur soviel:

Hab gerade kein Delphi zur Hand, aber entweder funktioniert

Listbox.items[i].selected := true

oder

ausblenden Delphi-Quelltext
1:
Listbox.selecteditem := Listbox.items[i]					


oder

ausblenden Delphi-Quelltext
1:
Listbox.selected := i					


Jörg.
Michael78 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20

WIN XP
D7 Prof
BeitragVerfasst: Sa 02.10.04 01:53 
Sorry wegen dem Quelltext, hab da wohl gepennt!

Funktioniert aber immer noch nicht!
pascal4free
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 47

Win2000
D8SSL
BeitragVerfasst: Sa 02.10.04 09:08 
ausblenden Delphi-Quelltext
1:
 listbox1.Selected[i]:=true; //i= dein itemindex					


steht sogar in der hilfe drin, und wenn du listbox1. eintippst steht es auch unter den codevorschlägen
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 02.10.04 09:12 
Hatte ich auch gedacht. Ich habe da ber den Fehler
ausblenden Quelltext
1:
Index überschreitet Maximum					

bekommen.
Ich bin aber ganz sicher, einen gültigen Wert genommen zu haben.
Habe das aber erstmal nicht weiter verfolgt.

Falls Michael den gleichen Fehler bekommt, können wir ja nochmal schauen.
pascal4free
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 47

Win2000
D8SSL
BeitragVerfasst: Sa 02.10.04 09:49 
afair musst du vom index 1 abziehen (listbox1.items.count-1 oder so), weil der index zählt immer 1 höher als die listbox items hat (oder so ähnlich)

und wenn du von hand einen wert eingibst sollte es an sich gehen (geht bei mir auf jeden fall)

edit: das hier geht schonmal

ausblenden Delphi-Quelltext
1:
2:
  i:=listbox1.items.count-1;
  listbox1.Selected[i]:=true;


edit2:

das hier ist in etwa das was du willst:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
    index: integer;
begin
 for i:=1 to listbox1.items.count-1
   do begin
     if listbox1.items[i]=edit1.text then
     index:=i;
   end;
 listbox1.selected[index]:=true;
end;
Michael78 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20

WIN XP
D7 Prof
BeitragVerfasst: Sa 02.10.04 10:11 
Danke für eure Tips, aber leider funktioniert das ganze immer noch nicht!

Kann man da nicht var gefunden benutzen, weil wenn gefunden=True dann soll er diesen Eintrag in der Listbox markieren.

Danke schon mal für Euer bemühen!!!!!!!
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Sa 02.10.04 10:21 
@pascal4free:
Ob du es glaubst oder nicht. Folgende Anweisung führt zu oben genannten Fehler:
ausblenden Quelltext
1:
     listbox1.Selected[1] := true;					

Es sind übrigens 6 Einträge enthalten.
Michael78 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20

WIN XP
D7 Prof
BeitragVerfasst: Sa 02.10.04 10:26 
Und wie mache ich das jetzt, das wenn ich im Edit-Feld was Eintrage, er mir diesen Eintrag in meiner Listbox markiert?

Komm einfach nicht weiter!
pascal4free
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 47

Win2000
D8SSL
BeitragVerfasst: Sa 02.10.04 10:31 
klar kannst du auch dein gefunden benutzen, doch ist das doch völlig unnötig, du kannst doch auch direkt in der if-schleife den index auf den wert von i setzen so wie ich es gemacht habe. ich sehe in dem gefunden keinen vorteil+

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
    index: integer;
    gefunden: boolean;
begin
 index:=0;
 gefunden:=false;
 for i:=0 to listbox1.items.count-1
   do begin
     if listbox1.items[i]=edit1.text then
       index:=i;
       gefunden:=true;
   end;
 if gefunden=true then
   listbox1.selected[index]:=true;
end;


das ganze jetzt noch anpassen dann sollte es gehen, wir sind hier an sich nicht da komplette codes zu liefern

@jasocul: das ist eigenartig, bei mir unter D7Pro geht genau das einwandfrei.


Zuletzt bearbeitet von pascal4free am Sa 02.10.04 10:34, insgesamt 1-mal bearbeitet
.Chef
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1112



BeitragVerfasst: Sa 02.10.04 10:34 
Hab den Code vom pascal4free grade mal getestet. Und es geht wunderbar ...

_________________
Die Antworten auf die 5 häufigsten Fragen:
1. Copy(), Pos(), Length() --- 2. DoubleBuffered:=True; --- 3. Application.ProcessMessages bzw. TThread --- 4. ShellExecute() --- 5. Keine Vergleiche von Real-Typen mit "="!
Michael78 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 20

WIN XP
D7 Prof
BeitragVerfasst: Sa 02.10.04 10:41 
Vielen Dank Pascal & Co.!!!

Funktioniert jetzt einwandfrei! Hatte einen Schreibfehler, deswegen hat er auch das ganze abgebrochen!

Also nochmals vielen Dank!!!!!!

CU Michael