Autor Beitrag
delphineuling
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 113

XP
wat dat
BeitragVerfasst: Fr 24.02.06 20:37 
Also ich will mit einem Button ein Item der Listbox löschen, aber das soll nicht Item Null sein, sondern nur das makierte.
Wie muss das dann aussehen?
Bis jetzt sieht es so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
 
procedure TForm1.Button3Click(Sender: TObject);
 begin
  listbox1.Items.Delete(0);
 end;

Muss ich doch eigentlich nicht viel ändern, oder?

Moderiert von user profile iconAXMD: Code- durch Delphi-Tags ersetzt
Moderiert von user profile iconUGrohne: Topic aus Sonstiges (Delphi) verschoben am Sa 25.02.2006 um 02:33
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Fr 24.02.06 20:40 
Zum Beitrag: bitte verwende Delphi- anstatt der Code-Tags.
Zum Thema: verwende ItemIndex der ListBox

AXMD
delphineuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 113

XP
wat dat
BeitragVerfasst: Fr 24.02.06 20:44 
Wie ich soll Delphi verwenden anstatt der Code Tags?
Wie sieht das denn danach aus?
Habs ja schon mit Itemindex versucht.
Sah dann so aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm1.Button3Click(Sender: TObject);
 begin
  listbox1.ItemIndex {und weiter?};
 end;


Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Fr 24.02.06 20:47 
Hallo
Versuchs mal so

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TFormLabordaten.BitBtn1Click(Sender: TObject);
Var z:Integer;
 begin
  z:=Listbox1.ItemIndex;
  listbox1.Items.Delete(z);
 end;


Gruß Andre
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Fr 24.02.06 20:47 
ItemIndex sollst du anstatt dem 0 verwenden... und über delphi-Tags kannst du in der Hilfe einiges nachlesen.

AXMD
delphineuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 113

XP
wat dat
BeitragVerfasst: Fr 24.02.06 22:09 
Wenn ich da einfach Itemindex eingebe funktioniert das nicht, habt ihr nich einen beispiel Code oder so?Versteh ich dann immer am besten!
Das andere Beispiel da, mit der Variable z und so: Löscht man da dann nicht alle Items der Listbox? Will ja nur ein makiertes Item löschen!
Andreas L.
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1703
Erhaltene Danke: 25

Windows Vista / Windows 10
Delphi 2009 Pro (JVCL, DragDrop, rmKlever, ICS, EmbeddedWB, DEC, Indy)
BeitragVerfasst: Fr 24.02.06 22:12 
ausblenden Delphi-Quelltext
1:
listbox1.Items.Delete(listbox1.itemindex);					


Evtl. musst du anstatt der gerundeten Klammer eine eckige Klammer verwenden: [ ]
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Fr 24.02.06 22:13 
Das mit z ist korrekt. Du kannst alternativ auch ListBox.ItemIndex übergeben (die ListBox ist hier wichtig - woher soll der Compiler sonst wissen welche ListBox ;))

AXMD
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Fr 24.02.06 22:35 
user profile icondelphineuling hat folgendes geschrieben:

Das andere Beispiel da, mit der Variable z und so: Löscht man da dann nicht alle Items der Listbox? Will ja nur ein makiertes Item löschen!


ItemIndex ist ein Integerwert der die markierte Zeile deiner Listbox übergibt, Angefangen bei 0 für Zeile 1
Bsp.: zeile 5 Markiert ItemIndex = 4
die Variable z hat jetzt also den wert 4

mit Listbox1.Items.Delete(z) löscht du jetzt also nur Zeile 5

Alles Klar ??

Gruß Andre
Grishnak
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 221

Windows XP Home
Delphi 7 PE, Delphi 2005 PE
BeitragVerfasst: Fr 24.02.06 22:54 
Aber vorsicht, wenn nichts (mehr) markiert ist, dann ist .ItemIndex nämlich -1 und das ergibt dann beim Löschversuch einen Fehler!

_________________
Mach' etwas idiotensicher und irgendjemand erfindet einen besseren Idioten!
der Berliner
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 417

Win Xp Home
delphi 2005
BeitragVerfasst: Fr 24.02.06 22:57 
user profile iconGrishnak hat folgendes geschrieben:
Aber vorsicht, wenn nichts (mehr) markiert ist, dann ist .ItemIndex nämlich -1 und das ergibt dann beim Löschversuch einen Fehler!



OK Ok
Dann packt man das ganze halt in die " onClick" Routine rein :D
delphineuling Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 113

XP
wat dat
BeitragVerfasst: Sa 25.02.06 02:19 
Ok Danke!!