Autor Beitrag
Hoellenwesen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Fr 30.01.04 14:48 
Hallo

ich hab in meinem mp3-player 2 formen: Form1 = Der Player und
Form2 = Die Playlist mit ListBox! ich möchte, wenn ich in der ListBox in der Form2 ein item markiere, den Playbutton im Form1 drücken, so das das lied abgespielt wird. ich habe es mit folgendem code versucht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
MediaPlayer1.FileName := Form2.ListBox1.Items[Form2.ListBox1.ItemIndex];
MediaPlayer1.Open;
MediaPlayer1.Play;
Timer1.Enabled := True;
Label1.Caption  := Form2.ListBox1.Items.Strings[Form2.ListBox1.Itemindex];




aber wenn ich das prog starte, das itam markiere und dann auf play drücke, kommt die fehlermeldung "Listenindex überschreitet das Maximum (-1)"
was mache ich falsch?

Danke im voraus!

Moderiert von user profile iconKlabautermann: B- durch Delphi-Tags ersetzt.


Zuletzt bearbeitet von Hoellenwesen am Fr 30.01.04 15:06, insgesamt 1-mal bearbeitet
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: Fr 30.01.04 14:58 
Hallo,

dein Titel enspricht nicht unseren Richtlinien. Diese sagen zu dem Thema:

Delphi-Forum Richtlinien hat folgendes geschrieben:

1.1 Beiträge
Bitte formuliere den Betreff Deiner Beiträge so, dass andere Mitglieder anhand dieser bereits das eigentliche Thema festmachen können. Beiträge wie etwa "Eine Anfängerfrage" oder "Weiß jemand, wie das geht?" lassen den Leser im Unklaren darüber, was das Thema der Diskussion ist. Eine Pseudocodezeile oder die Nennung des Objektes, um welches es sich in dem Beitrag handelt, helfen da schon mehr weiter.


Ändere bitte das den Titel, indem du deinen ersten Beitrag dieses Threads noch einmal Editierst. Einfach bei dem Beitrag auf Edit clicken, den Titel ändern und wieder auf Absenden.

Gruß
Klabautermann
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Fr 30.01.04 18:23 
Kann es sein, dass deine Form2 den Fokus verliert, sobald du den Knopf auf Form1 anklickst?

VCL-Referenz hat folgendes geschrieben:
Wenn kein Eintrag ausgewählt ist, hat ItemIndex den Wert -1


Ich würde dir noch ratenMediaPlayer1.FileName := Form2.ListBox1.Items.Strings[Form2.ListBox1.ItemIndex]; zu benutzen.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Hoellenwesen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Fr 30.01.04 18:46 
Hallo,

ich glaub ich kapier das immernoch nicht, weil es klappt irgendwie noch nciht. ich weiß nicht ob ich jetzt noch mehr falsch gemacht hab als vorher, aber ich poste mal den code, den ich jetzt probiert hab:


procedure TForm1.Button1Click(Sender: TObject);
var i: integer;
begin
for i := 0 to Form2.ListBox1.Items.Count - 1 do
if Form2.ListBox1.Selected[i] then
MediaPlayer1.FileName := Form2.ListBox1.Items.Strings[Form2.ListBox1.ItemIndex];
MediaPlayer1.Open;
MediaPlayer1.Play;
Timer1.Enabled := True;
Label3.Caption := Form2.ListBox1.Items.Strings[Form2.ListBox1.ItemIndex];
end;



wäre wirklich nett, wenn du mir code posten könntest, weil ich komm hier echt nciht weiter.

Danke
derDoc
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 623

Win Vista Prof
D2007 Prof
BeitragVerfasst: Fr 30.01.04 19:52 
Ich habe das nochmal getestet. Bei mir geht das einwandfrei.

Folgendes würde ich dir anraten:
Du kannst einfach
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button1Click(Sender: TObject);
begin
  MediaPlayer1.FileName := Form2.ListBox1.Items.Strings[Form2.ListBox1.ItemIndex];
  MediaPlayer1.Open;
  MediaPlayer1.Play;
  Timer1.Enabled := True;
  Label1.Caption := Form2.ListBox1.Items.Strings[Form2.ListBox1.ItemIndex];
end;
benutzen, denn ListBoxXYZ.ItemIndex gibt den Index des markierten Eintrags zurück.

Eventuell kannst du noch prüfen ob Form2.ListBox1.ItemIndex >= 0 ist, damit keine Fehler kommen.

_________________
MfG derDoc
There are only 10 types of people: those who understand binary and those who don't.
Hoellenwesen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 17



BeitragVerfasst: Fr 30.01.04 20:04 
Hey cool,

jetzt funktioniert es wunderbar. ist ja seltsam.
also vielen dank für deine hilfe!!

MfG