Autor Beitrag
Peteroramer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Windows XP
Delphi 7
BeitragVerfasst: Di 28.03.06 18:49 
Hallo,

ich will von einer Listbox, wo die Lider mit Quellpfad, aufgelistet sind abspielen. Ich habe dazu gefunden : www.krazz.net/retnyg...etnyg/tut/mptut1.htm aber aus irgend einem grund funktioniert das nicht. Ich bekomme immer die Fehlermeldung, dass die Listbox den Speicher überschreitet, obwohl nur 7 Lider drin sind.
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Di 28.03.06 18:56 
Ohne Quellcode, wo der Fehler auftritt wirds schwierig dir zu helfen. Möglicherweise hast du nicht daran gedacht, dass der Index Null-terminiert ist ?!
Poste doch mal den Quellcode-Auszug und die genaue Fehlermeldung...
Peteroramer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Windows XP
Delphi 7
BeitragVerfasst: Di 28.03.06 19:07 
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:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, MPlayer, ComCtrls, ShellCtrls, StdCtrls, ImgList, Buttons,
  ExtCtrls, ShellApi;

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Button1: TButton;
    Button2: TButton;
    GroupBox2: TGroupBox;
    ListBox1: TListBox;
    ShellTreeView1: TShellTreeView;
    MediaPlayer1: TMediaPlayer;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    GroupBox3: TGroupBox;
    Image1: TImage;
    Button10: TButton;
    Button8: TButton;
    procedure Button4Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure ListBox1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
    Procedure AddToPlayList(s:string);
    procedure PlayFile(s:string);
    Procedure WMDropFiles (Var aMsg: tMessage);  message WM_DROPFILES;
  end;

var
  Form1: TForm1;
  playList: TStringList;
implementation

{$R *.dfm}

Procedure TForm1.WMDropFiles (Var aMsg: tMessage);
Var
  Idx, Size, FileCount: Integer;
  Filename: pChar;
Begin
  Inherited;
  FileCount := DragQueryFile (aMsg.WParam, $FFFFFFFF, nil, 255);
  For Idx := 0 To FileCount -1 Do Begin
    Size := DragQueryFile (aMsg.WParam, Idx, nil, 0) + 1;
    Filename := StrAlloc (Size);
    If DragQueryFile (aMsg.WParam, Idx, Filename, Size) = 1 Then  { nothing }
    else  AddToPlayList (pChar (Filename));
    StrDispose (Filename);
  End;
  DragFinish (aMsg.WParam);
End;

Procedure TForm1.AddToPlayList(s:string);
begin
   playList.Add(s);
   ListBox1.Items.Add(s);
end;

procedure FindFiles(const Path: String; const Ext: array of String; Result: TStrings);
  procedure SearchFiles(const Path: String; const Ext: array of String; Result: TStrings);
  var
    SR: TSearchRec;
    I:  Integer;
  begin
    if FindFirst(Path + '*.*', faAnyFile, SR) = 0 then
    begin
      repeat
        if (SR.Name <> '.') and (SR.Name <> '..') then
        begin
          if (SR.Attr and faDirectory) = faDirectory then
            SearchFiles(IncludeTrailingPathDelimiter(Path + SR.Name), Ext, Result)
          else
            for I := Low(Ext) to High(Ext) do
              if SameText(Ext[I], ExtractFileExt(SR.Name)) then
              begin
                Result.Add(Path + SR.Name);
                Break;
              end;
        end;
      until FindNext(SR) <> 0;
      FindClose(SR);
    end;
  end;

begin
  Result.Clear;
  SearchFiles(IncludeTrailingPathDelimiter(Path), Ext, Result);
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
 close;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 edit1.Text:=ShellTreeView1.Path;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 edit1.Text:='';
end;

procedure TForm1.Button8Click(Sender: TObject);
var i:string;
begin
 FindFiles(edit1.Text,['.mp3'], ListBox1.Items);
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
 ListBox1.Items.clear;
end;

procedure TForm1.Button3Click(Sender: TObject);
var i:string;
begin
    mediaplayer1.FileName := 'C:\Dokumente und Einstellungen\Peter Paul\Desktop\Abwärts\terrorbeat.mp3';
  mediaplayer1.Open;
  mediaplayer1.play;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   DragAcceptFiles (Handle, True);   // drag und drop akzeptieren
   playList := TStringList.Create;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
   playList.Free;
end;

procedure TForm1.PlayFile(s:string);
begin
   mediaplayer1.Close;
   mediaplayer1.FileName := s;
   mediaplayer1.Open;
   mediaplayer1.play;
end;

procedure TForm1.ListBox1Click(Sender: TObject);
var i : integer;
begin
  for i := 0 to listbox1.Count - 1 do
    if listbox1.Selected[i] then break;
  { nun haben wir in i die nummer der selektierten Zeile
    da Listbox und Playlist eine identische Reihe der Einträge und gleiche Sortierung
    vorweisen, können wir mit dem erhaltenen index den richtigen Eintrag der Playlist
    auslesen. }

  if fileexists(Playlist.Strings[i]) then PlayFile(Playlist.Strings[i]);
end;

end.



und die Fehlermeldung ist diese

Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
Einloggen, um Attachments anzusehen!
Peteroramer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Windows XP
Delphi 7
BeitragVerfasst: Di 28.03.06 19:10 
Es muss doch gehen, das ich bei den Button8Click sage, dass er den Feldinhalt von der Listbox ausgibt. Aber wie schaffe ich es, dass er den Inhalt von der Listbox als Feld ansieht und diese abspielt?
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Di 28.03.06 19:20 
user profile iconPeteroramer hat folgendes geschrieben:
Es muss doch gehen, das ich bei den Button8Click sage, dass er den Feldinhalt von der Listbox ausgibt. Aber wie schaffe ich es, dass er den Inhalt von der Listbox als Feld ansieht und diese abspielt?


Was verstehst du unter Feldinhalt bzw Feld?
Hat das noch was mit deinem ersten Problem zu tun ?
Peteroramer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Windows XP
Delphi 7
BeitragVerfasst: Di 28.03.06 19:43 
Naja, ich bekomme doch diese Fehlermeldung. Warum das so ist, weiß ich bis jetzt nicht. Jetzt habe ich mir gedacht das es doch auch so gehen muss.

mediaplayer1.Close;
mediaplayer1.FileName:=Listbox1.Items.Strings[s];
mediaplayer1.Open;

dafür müsste ich aber den Inhalt der Listbox in einem array abspeichern?
aber wie?
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 28.03.06 20:30 
Das ausgewählte Item ist:
ausblenden Delphi-Quelltext
1:
s := Listbox1.Items[Listbox1.ItemIndex];					
Peteroramer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Windows XP
Delphi 7
BeitragVerfasst: Di 28.03.06 20:47 
Und wo setzte ich den Quellcode rein?

In der procedure für den Buttom oder wo anders?
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 28.03.06 20:49 
Am besten ins OnClose deiner Form. Natürlich da, wo du ihn brauchst.
Peteroramer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Windows XP
Delphi 7
BeitragVerfasst: Di 28.03.06 20:58 
ich habe jetzt eine procedure geschrieben die so aussieht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
 var ItemIndex:integer;s:string;
 s := Listbox1.Items[Listbox1.ItemIndex];
 mediaplayer1.Close;
 mediaplayer1.FileName:=Listbox1.Items.Strings[s];
 mediaplayer1.Open;


nun heißt es aber, array typ erforderlich. Weiß aber nicht wie ich diese bestimmen soll

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
Peteroramer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29

Windows XP
Delphi 7
BeitragVerfasst: Di 28.03.06 21:02 
sorry die procedure heißt:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button3Click(Sender: TObject);
var ItemIndex:integer;s:string;
begin
 s := Listbox1.Items[Listbox1.ItemIndex];
 mediaplayer1.Close;
 mediaplayer1.FileName:=Listbox1.Itemindex[s];
 mediaplayer1.Open;
end;


und dann kommt: [Fehler]Unit1.pas(141):Array-Typ erforderlich

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt