Autor Beitrag
Raezor
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 25.03.07 09:58 
Habe in einer Listbox 10 verschiedene Items.
Wenn ich auf ein Item selektiere und auf einen button klicke,
soll die selektierte item ind den mediaplayer geladen werden.
Wie muss das aussehen?

(Button)
ausblenden Quelltext
1:
MediaPlayer1.FileName := Listbox1.items[-1];					


Dazu kommt dann immer die Meldung, wenn ich auf den button klicke -Listindex überschreitung
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: So 25.03.07 10:30 
Stell zu erstmal fest, ob überhaupt was in der Listbox steht & ein Item selektiert worden ist, ansonsten gibt es eine nette Zugriffsverletzung.
Mach es z.B. so:
ausblenden Delphi-Quelltext
1:
2:
3:
 if Listbox1.Items.Count > 0 then     // ist die Listbox gefüllt?
   if Listbox1.ItemIndex <> -1 then   // ist ein Eintrag ausgewählt?
     MediaPlayer1.FileName := Listbox1.Items[Listbox1.ItemIndex];

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 25.03.07 10:54 
Hallo,

wenn Listbox1.ItemIndex <> -1 ist, dann ist Count > 0 :wink:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Dunkel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 682

Mac OS X Snow Leopard
Xcode 3.1
BeitragVerfasst: So 25.03.07 11:02 
user profile iconLannes hat folgendes geschrieben:
Hallo,

wenn Listbox1.ItemIndex <> -1 ist, dann ist Count > 0 :wink:

Es ist wohl noch zu früh am Morgen... was willst Du damit sagen? Ich seh' zumindest keinen Fehler in meinem Code.

Edit:
...achso, verstehe, ja hast recht!

_________________
Ich streite einsam mich mit dieser Oberflächenwelt
Gutes sei ein löblich Brot von dem ich zehre - bis zum Tod [Das Ich - Im Ich]
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 25.03.07 12:00 
ok klappt recht gut.
doch wenn ich ein markiertes item löschen will, muss ich statt add was einsetzten?
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 25.03.07 12:04 
Hallo,

löschen >>> delete :gruebel:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 25.03.07 12:27 
oh sorry, ich meine das so:

ListBox1.Items.delet(selektiertes löschen);
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: So 25.03.07 13:10 
Hallo,

ausblenden Delphi-Quelltext
1:
procedure Delete(Index: Integer); virtualabstract;					


Delete fordert den Index des Items das gelöscht werden soll.
ListBox.ItemIndex liefert Dir den Index des selektierten Items.
Also:
ausblenden Delphi-Quelltext
1:
ListBox.Items.Delete(ListBox.ItemIndex);					

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 25.03.07 14:40 
wenn ich das dem button gebe kommt;

[Fataler Fehler] Ausgabedatei 'D:\delphi\mediaplayer\Project1.exe' kann nicht erstellt werden
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 25.03.07 14:45 
Wenn das der einzige Fehler ist, dann läuft das Programm wahrscheinlich gerade...

_________________
We are, we were and will not be.
Raezor Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 54

Status:
Administrator des Mondes
BeitragVerfasst: So 25.03.07 14:48 
hä?
Wie gerade? ->schräg?!?
Muss man das verstehen?

Edit:
Ach so...du meinst es wird gerade verwendet bzw. benutzt

-- ok jetzt gehts
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: So 25.03.07 15:06 
Duden Deutsches Universal Wörterbuch A-Z hat folgendes geschrieben:
ge|ra|de [...] II. <Adv.> a) <zeitlich> in diesem Augenblick, soeben, momentan [...]
;-)

_________________
We are, we were and will not be.