Autor Beitrag
pascalsv
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133

Win XP Prof. SP2 / Windows 7
Visual Studio 2008 / Silverlight 3 / Silverlight 4 Beta
BeitragVerfasst: Sa 05.08.06 17:30 
Hallo zusammen,

ich kann mich erinnern, mit einer TListBox vor einigen Jahren eine App geschrieben zu haben, wo ich Zusatzinfos zu den Einträgen in der Listbox speichern konnte. Bsp:

ListBox-Eintrag_|_Zusatz_______________________
-----------------------------------------------
musiktitel.mp3__|_c:\meine_musik\musiktitel.mp3
musiktitel2.mp3_|_c:\mp3s\amore.mp3

Die Spalte mit den Zusatzinfos war dabei nicht sichtbar, liess sich aber über den Index der ListBox einfach ansprechen...

Wie ging das noch mal??

Danke,

Pascal
Born-to-Frag
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1094

Win XP SP2, Win 2000 SP4
Delphi 7, 2k5
BeitragVerfasst: Sa 05.08.06 18:38 
ListBox1.Items.AddObject(.., ..); ?

Damit kannst du zu jedem Eintrag ein Object hinzufügen.. Damit sollte es machbar sein ;)

_________________
Theorie ist wenn man alles weiß, aber nichts funktioniert. Praxis ist wenn alles funktioniert, aber niemand weiß warum.
Microsoft vereint Theorie und Praxis: Nichts funktioniert und niemand weiß warum.
pascalsv Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133

Win XP Prof. SP2 / Windows 7
Visual Studio 2008 / Silverlight 3 / Silverlight 4 Beta
BeitragVerfasst: Fr 11.08.06 09:37 
Alaska,

dabei treten jedoch weitere Fragen auf. Meine Idee war nun, in eine Zeile der ListBox ID-Tags und als Objekt den Pfad zu der Datei abzulegen.

Mein Code dazu:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
if findfirst(Verzeichnis+'*.*',faAnyFile,f)=0 then
  begin
   if findfirst(Verzeichnis+'*.mp3',faAnyFile,f2)=0 then {falls *.htm Dateien gefunden}
    begin
      ...
      mp3Liste.Items.Add(ID3.Artist+' - '+ID3.Title);
      mp3Liste.Items.AddObject(Verzeichnis+f2.Name, TString); //hier rummst es natürlich! Was für ein Objekt kommt hier rein???
      while findnext(f2)=0 do begin
        ...
        mp3Liste.Items.Add(ID3.Artist+' - '+ID3.Title);
        mp3Liste.Items.AddObject(Verzeichnis+f2.Name, TString);
      end;
    end;
    while findnext(f)=0 do {Verzeichniserkennung}
    ...
  end;
FindClose(f);


Der Pfad ist doch ein String, oder? Warum geht dann TString (davon abgesehen, dass es den nicht zu geben scheint) nicht?

Danke,

Pascal
Jakob Schöttl
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 929
Erhaltene Danke: 1


Delphi 7 Professional
BeitragVerfasst: Fr 11.08.06 10:06 
Also ich hoffe ich versteh dich richtig.
ein Objekt muss natürlich von TObject abgeleitet sein, deshalb also zB. TStrings. Einen string kannst du natürlich nicht zuweisen. Ich weiß auch nicht, was du am besten machst, wenn du nur einen string als information hast. Zur Not könntest du ein TLabel nehmen, ist aber natürlich auch unelegant.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 11.08.06 10:27 
Das stimmt so nicht ganz. Du brauchst nicht zwingend ein Objekt, sonderen einen Zeiger auf beliebige Daten.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure TForm1.Button1Click(Sender: TObject);
begin
  //Hinzufügen
  Listbox1.Items.AddObject('Sichtbarer Text',TObject(pchar('Wichtige Daten')))
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
  //Auslesen
  ShowMessage(pchar(ListBox1.Items.Objects[ListBox1.itemIndex]));
end;


Statt der Texte kannst du natürlicha auch Variablen nehmen. Diese Typecasts tun übrigens nichts weiter, als den Compiler ruhigzustellen. Zeiger sind sowohl String, PChar als auch TObject.

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
pascalsv Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133

Win XP Prof. SP2 / Windows 7
Visual Studio 2008 / Silverlight 3 / Silverlight 4 Beta
BeitragVerfasst: Mi 16.08.06 12:53 
Funzt super, danke!!

Pascal
smepal
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win XP, Linux Mandbrake,SUSE 10.1, SUSE 9 PE, DEBIAN, Win 2000 Pro, Win XP Pro
Delphi
BeitragVerfasst: Mi 16.08.06 18:24 
Falls es dich interessiert:

Ich bin gerade dabei eine Playlist Komponente zu Programmieren, die dein Problem ganz einfach lösen würde und noch dazu m3u Playlists unterstützt.

Hier die Unit:
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:
unit playlist;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, StdCtrls, Buttons, ExtCtrls;

type
  TInfos = class
    Filename:string;
  public
    property Str:string read Filename write Filename;
  end;
type
 TTracks = record
  Title: String;
  time: String;
  path: String;
  no: Integer;
 end;




type
  TPlayList = class(TStringGrid)

  private
    function GetTracks(index:integer):TTracks; { Private-Deklarationen }
  protected

    { Protected-Deklarationen }
  public
  constructor Create (AOwner: TComponent); override;
  Procedure KeyDown(var Key: Word; Shift: TShiftState); override;
   procedure DblClick; override;
    { Public-Deklarationen }


  published
   procedure DeleteRow (RowNumber : Integer);
   procedure addFile (pfad, dauer, titel: String);
   procedure openM3u (m3u: String);
   property Track[index:integer]:TTracks read GetTracks;
   { Published-Deklarationen }
  end;

procedure Register;



implementation

constructor TPlaylist.Create(AOwner: TComponent);
var option: TGridOptions;
begin
inherited Create (AOwner);
options := [gorowselect] + [gocolsizing]+ [gofixedvertline] + [gofixedhorzline] + [govertline] + [gohorzline];

rowcount := 2;
 colcount := 3;
 fixedcols := 0;
 fixedrows := 1;
 defaultrowheight := 15;
 rowheights[0] := 18;
Cells[1,0] := 'Title';
Cells[2,0] := 'Length';
Cells[0,0] := 'No';
ColWidths[0] := 30;
colwidths[1] := 200;
colwidths[2] := 50;


end;

function TPlaylist.GetTracks (index: Integer): TTracks;
begin
Result.no := strtoint(cells[0, index]);
Result.Title:= cells[1, index];
  Result.time := cells[2, index];
  Result.path := cells[3, index];

end;

procedure TPlaylist.openM3u (m3u: String);
var i, position: Integer;
 list: Tstringlist;
 path, time, title: String;
begin
list := TStringlist.Create;
list.LoadFromFile(m3u);

if list.Strings[0] = '#EXTM3U' then
   begin
      for i := 0 to list.Count - 1 do
        begin
        position := ansipos ('#EXTINF:' , list.Strings[i]);
                 if position = 1 then
                 begin
                 time := copy(list.strings[i],9,3);
                 title := copy(list.strings[i],13,1000);
                 path := list.Strings[i+1];
                 addfile(path,time,title);
                 end;
        end;
end;
end;

procedure TPlaylist.addFile (pfad, dauer, titel: String);
var i: Integer;
mo: TInfos;
begin
rowcount := rowcount + 1;




mo:=TInfos.create;
    mo.Filename:='';
    Objects[rowcount-2,3]:=mo;


cells[1, rowcount-2] := titel;
cells[2, rowcount-2] := dauer;
cells[0,rowcount-2] := inttostr(rowcount - 2);
cells[3,rowcount-2] := pfad;

end;

procedure Tplaylist.DeleteRow(RowNumber : Integer);
var
i : Integer;
begin



  for i := RowNumber to RowCount - 2 do
    Rows[i].Assign(Rows[i+ 1]);


  Rows[RowCount-1].Clear;
  RowCount := RowCount - 1;
 for i := 1 to rowcount do
 cells[0,i] := inttostr(i);
end;

procedure TPlaylist.KeyDown(var Key: Word; Shift: TShiftState);
begin
if key = vk_delete then
   if (row <> 0) then
      deleterow(row);
end;

procedure Register;
begin
  RegisterComponents('Standard', [TPlayList]);
end;

procedure TPlaylist.DblClick;
begin
gettracks(row);

end;


end.


Ist allerdings noch nicht ganz fertig, aber über playlist.addfile oderplaylist.openm3u kannst du schon eine Menge erreichen.

playlist.tracks[3].path gibt dann zb den Pfad zurück!
pascalsv Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133

Win XP Prof. SP2 / Windows 7
Visual Studio 2008 / Silverlight 3 / Silverlight 4 Beta
BeitragVerfasst: Do 17.08.06 11:40 
Klingt gut, so habe ich z.B. die PlayListe gespeichert (nicht, dass es was besonderes wäre... :P );
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure TfMain.bPlayListSaveClick(Sender: TObject);
var Datei : TextFile;
    i : integer;
begin
  SaveDialog.Filter := '*.m3u';
  if (mp3List.Items.Count > 0) and (SaveDialog.Execute) then begin
    try
      AssignFile(Datei, SaveDialog.FileName+'.m3u');
      Rewrite(Datei);
      Writeln(Datei, '#EXTM3U');
      for i := 0 to mp3List.items.count-1 do begin
        Writeln(Datei, '#EXTINF:'+mp3List.Items[i]);
        Writeln(Datei, PChar(mp3List.Items.Objects[i]));
      end
    finally
      CloseFile(Datei);
      ScrollOutPanel(pnlPlayliste, bPlayliste);
    end;
  end;
end;


Ich werde mir Deinen Code jetzt mal zu Gemüte führen...

Pascal
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Do 17.08.06 11:49 
Nur mal als kleine Anmerkung zu den m3u-Playlisten. Wenn ihr die ladet und anschließend mit den hier gezeigten Code-Schnippseln das wieder speichert, können Informationen verloren gehen, denn es gibt noch Zusatzinformationen wie überschneidungen etc, die ihr beachten solllten! (Am besten zieht euch die Spezifikation darüber zu gemüte)
pascalsv Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 133

Win XP Prof. SP2 / Windows 7
Visual Studio 2008 / Silverlight 3 / Silverlight 4 Beta
BeitragVerfasst: Do 17.08.06 12:15 
Heiko, Du hast völlig recht. Siehe WinAmp-Specs:
Zitat:
Extended M3U

Let's first look at an extended M3U file then I will describe everything below

sample2.m3u

code:
#EXTM3U
#EXTINF:233,Everclear - So Much For The Afterglow
Alternative\everclear - SMFTA.mp3
#EXTINF:227,Weird Al - Everything You Know Is Wrong
Comedy\Weird Al - Everything You Know Is Wrong.mp3
#EXTINF:187,Weird Al Yankovic - This is the Life
Weird Al - This Is The Life.mp3
#EXTINF:129,Weird Al: Bad Hair Day - Gump
www.site.com/~user/gump.mp3
#EXTINF:-1,My Cool Stream
www.site.com:8000/listen.pls



Explanation of entries:
#EXTM3U At the VERY top of the Extended M3U file is this header, which signifies this is an extended M3U file. '#EXTM3U" must be all capital letters.

#EXTINF:233,Everclear - So Much For The Afterglow: This is the line that tends to confuse people. Let's break it up into parts
- #EXTINF:: This signifies this is an Extended Information field. It ends with a colon (:).
- 233,: This is the time of the file in seconds followed by a comma. (233 seconds = 3:53). On the last entry there is a negative one, this is usually seen on streams, it tells the program to ignore the time entry.
- Everclear - So Much For The Afterglow: Title to display. This is usually the title read from the file name or ID3 tags. This also can be the name of a stream. No characters follow the title.
Alternative\everclear - SMFTA.mp3: File location as described above with basic playlists.


Entsprechend werde ich die Speicherroutine ändern.

Pascal
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Do 17.08.06 12:48 
Wenn ichs gerade nicht übersehen habe, ist es immer noch nicht alles. Es gibt noch eigenschaften für Übergänge zwischen den Titeln (Stichwort Faden ;) ).