Autor Beitrag
DelphiNoob
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152

Win 2003 Server
D7 Ent
BeitragVerfasst: Do 13.03.03 15:33 
Hi,

hab es in der Titelzeile ja angesprochen: Ich will ein bestimmtes Item aus einer ListView löschen!

Angenommen ich hab 3 Items da drin, das eine hat die Caption "hallo" das zweite "tach" und das dritte "aloha".

Jetzt möchte ich das per schleife (oder ähnliches) das item mit der caption "tach" gelöscht wird! Nur ich hab keinen plan wie...

Ich hab hier die mega billig variante, wie ich mir das vorstelle, aber das funzt nicht, und ist bestimmt irgendwas falsch.

ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
repeat
If Clientlist.Items(i).Text = Wort then
begin
Clientlist.Items.Delete(i);
i:=-1;
end
else i:=i+1;
until i = -1;


plz help!

Mfg
DelphiNoob
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 13.03.03 15:38 
schau dir mal Indexof an

ausblenden Quelltext
1:
if listbox1.items.indexof('Hallo')<>-1 then listbox1.items.delete(listbox1.items.indexof('Hallo'))					

ungetestet, direkt ins forum geklimpert

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
Klabautermann
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Veteran
Beiträge: 6366
Erhaltene Danke: 60

Windows 7, Ubuntu
Delphi 7 Prof.
BeitragVerfasst: Do 13.03.03 15:38 
Hallo,
ich habe den Code jetzt nur flüchtig in augenschein genommen aber was mir auffällt, ist das du nach den Items eine Runde Klammer gemacht hast. Das muss eine Eckige sein:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
repeat
If Clientlist.Items[i].Text = Wort then
begin
Clientlist.Items.Delete(i);
i:=-1;
end
else i:=i+1;
until i = -1;


Gruß
Klabautermann
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Do 13.03.03 15:40 
Hi,


ich schätze du könntest das so formulieren:
ausblenden Quelltext
1:
2:
3:
4:
5:
for i := 0 to Clientlist.count-1 do if sameText(Clientlist.items[i], wort) then
begin
  Clientlist.items.delete(i);
  break;
end;


vielleicht hilft dir das!?

Achja: anstatt i:= i +1 kanst du auch inc(i); (dec(i) für -1 oder inc(i,4) für +4).

[edit]: macht doch sinn
DelphiNoob Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152

Win 2003 Server
D7 Ent
BeitragVerfasst: Do 13.03.03 15:52 
Hi,

ich hab jetzt mal den letzten Vorschlag eingebaut, aber das prob ist: Das Icon wird nicht gelöscht?!?!
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Do 13.03.03 16:34 
sorry verlesen, hast ja Listview gemeint. :oops:
wie meinst du das mit dem Icon?

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
DelphiNoob Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152

Win 2003 Server
D7 Ent
BeitragVerfasst: Do 13.03.03 16:41 
Also ich habe ein bestimmtes Item im Listview.

Z.b. ein einfaches Icon mit dem text drunter "hallo"...

dann habe ich vieleicht noch 3 oder 4 andere Items.

Jetzt möchte ich per schleife eines löschen...

also If TextUnterDemIcon = MeinText then löschen...
nur mal so als skizze!

Mfg
DelphiNoob
maximus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 896

Win XP, Suse 8.1
Delphi 4/7/8 alles prof
BeitragVerfasst: Do 13.03.03 18:33 
Meinst du nu Icon oder Item, oder ist das für dich das gleiche?

Wie wärs mit nem breakPoint und dann schauste mal wo er durchläuft!

Vielleicht hilft ein listView.refresh?
DelphiNoob Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152

Win 2003 Server
D7 Ent
BeitragVerfasst: Do 13.03.03 20:32 
DelphiNoob hat folgendes geschrieben:
Also ich habe ein bestimmtes Item im Listview.

Z.b. ein einfaches Icon mit dem text drunter "hallo"...


Item:

Icon + Text
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Fr 14.03.03 09:42 
*ehrlich bin*
Sorry hab deinen Code gestern irgendwie nicht richtig durchgelesen.
Aber wenn du du Clientlist schreibst - denke ich ich nicht an an Listview - die Bennenung find ich nicht so gut und verwirrend, aber egal
Zitat:

If Clientlist.Items(i).Text = Wort then

das mit den eckigen Klammern hat dir Klabautermann schon gesagt.
aber was soll Text sein? Wenn du ein wenig in der Oh blätterst und die Eigenschaften ein wenig durchlist, gibst da kein items.text (zumindestens nicht unter D5, was ich hier grad hab) - Caption ist das was du suchst.

Ich habe den Code von maximus probiert. Er hat vielleciht wie ich auch an eine List gedacht und es waren ein paar kleine Fehler drin, die du aber mit den Fehlermeldugnen des Compilers schnell selber findest und beheben kannst.
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var I:integer;
begin
for i := 0 to Clientlist.items.count-1 do
  if sameText(Clientlist.items[i].caption, 'Hallo') then
    begin
      Clientlist.items.delete(i);
      break;
    end;
end;

funktioniert. das item wird aus dem listview gelöscht und das icon ist auch nicht mehr zusehen ... oder wo ist das Problem?

Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
iaby
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 21



BeitragVerfasst: Fr 14.03.03 10:04 
hier mal meine variante:
die zeile      Clientlist.items.delete(i);
mit dieserclientlist.items[i].delete
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Fr 14.03.03 10:12 
DelphiNoob hat folgendes geschrieben:
Jetzt möchte ich per schleife eines löschen...

Warum möchtest Du eine Schleife benutzen wenn Du nur ein Item löschen willst?

Gruß
TINO
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: Fr 14.03.03 10:20 
Tino hat folgendes geschrieben:
DelphiNoob hat folgendes geschrieben:
Jetzt möchte ich per schleife eines löschen...

Warum möchtest Du eine Schleife benutzen wenn Du nur ein Item löschen willst?


Hallo Tino, ich denke mal, das er die Schleife braucht, um des entsprechende Item überhaupt erst mal zu finden.

es würde aber auch ohne Schleife gehen:

ausblenden Quelltext
1:
2:
3:
4:
5:
Var listitem:TListitem;
begin
  listitem:=Clientlist.FindCaption(0,'hallo',false,false,false);
  if listitem<>Nil then listitem.delete;
end;


Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
DelphiNoob Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152

Win 2003 Server
D7 Ent
BeitragVerfasst: So 23.03.03 11:11 
ausblenden Quelltext
1:
2:
3:
listitem:=ListView1.FindCaption(0,Commblock.User,false,false,false);
if listitem<>Nil then listitem.delete;
ListView1.Update;


So, ich hab das so eingebaut, aber leider funktioniert das nicht wirklich! Es kommt kein Fehler, der Code scheint meiner Ansicht nach auch zu stimmen, nur das "Item" verschwindet nicht *grummel*.

Ideen?
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: So 23.03.03 11:28 
Versuch mal folgendes:
ausblenden Quelltext
1:
listitem := ListView1.FindCaption (0, Commblock.User, False, False,  True);					

Gruß
Tino
DelphiNoob Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152

Win 2003 Server
D7 Ent
BeitragVerfasst: So 23.03.03 11:31 
ICH LIEBE DICH!!!!

*g*

Ok, nicht wirklich, aber DANKEEEEEEEEEEEEEEEEEEEEEE!

------

Frage:

Was hat das jetzt genau bewirkt? Ich will ja auch den Hintergrund verstehen / wissen.
Keldorn
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 2266
Erhaltene Danke: 4

Vista
D6 Prof, D 2005 Pro, D2007 Pro, DelphiXE2 Pro
BeitragVerfasst: So 23.03.03 15:35 
DelphiNoob hat folgendes geschrieben:

Frage:

Was hat das jetzt genau bewirkt? Ich will ja auch den Hintergrund verstehen / wissen.

na, bei dir ist wohl die f1-Taste kaputt? cursor auf Findcaption und F1-drück und :D alle Paramter erklärt.

Obwohl, so wie ich die Sache verstehe, hats eigentlich keinen Sinn Wrap auf true zu setzen, wenn du beim 1. Eintrag anfängst zu suchen.
kann es sein, das du versucht hast den ersten eintrag zu löschen?
wenn du Inclusive auf true setzt, müßte es auch gehen.
ausblenden Quelltext
1:
listitem := ListView1.FindCaption (0, Commblock.User, False, True,  False);					


Mfg Frank

_________________
Lükes Grundlage der Programmierung: Es wird nicht funktionieren.
(Murphy)
DelphiNoob Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 152

Win 2003 Server
D7 Ent
BeitragVerfasst: So 23.03.03 15:53 
Es ist Variabel welcher Eintrag gelöscht wird! Je nachdem welcher User sich abmeldet. Wenn das der ist der sich als 10tes Angemeldet hat, ist es halt das 10te Item was gelöscht wird... wenn er der 5te war, dann das 5te Item, usw usw usw.

Mfg
Delphi Noob