![]() |
TPlaylist neue Komponente!
Hallo,
ich programmiere gerade eine neu Komponente, die die Funktion einer Playlist haben soll. Als Vorlage dafür habe ich ein TStringgrid genommen, das ich nun modifiziere bzw erweitere. Nun möchte ich, dass wenn man der Playlist einen Track hinzufügt, die Daten in Form eines Arrays oder ähnlichem nachher abrufbar sind. (Die add-Procedur findet ihr unten) D.h. dieser Code sollte zum Beispiel Infos von Track1 zurückgeben:
Delphi-Quellcode:
Wie kann ich das realisieren?
playlist.tracks[1].path
playlist.tracks[1].name playlist.tracks[1].time
Delphi-Quellcode:
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 TPlayList = class(TStringGrid) private { Private-Deklarationen } protected procedure Click; override; { Protected-Deklarationen } public constructor Create (AOwner: TComponent); override; { Public-Deklarationen } published procedure DeleteRow (RowNumber : Integer); procedure addFile (pfad, dauer, titel: String); { Published-Deklarationen } end; procedure Register; implementation constructor TPlaylist.Create(AOwner: TComponent); begin inherited Create (AOwner); rowcount := 2; colcount := 3; fixedcols := 0; fixedrows := 1; defaultrowheight := 15; rowheights[0] := 18; Cells[0,0] := 'Title'; Cells[1,0] := 'Length'; Cells[2,0] := 'x'; ColWidths[0] := 200; colwidths[1] := 50; colwidths[2] := defaultrowheight; end; procedure TPlaylist.addFile (pfad, dauer, titel: String); var i: Integer; mo: TInfos; begin rowcount := rowcount + 1; mo:=TInfos.create; mo.Filename:=''; Objects[rowcount-1,3]:=mo; cells[0, rowcount-1] := titel; cells[1, rowcount-1] := dauer; cells[2,rowcount-1] := 'x'; cells[3,rowcount-1] := 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; end; procedure TPlaylist.Click; begin if (col = 0) or (col = 1) then selection := TGridRect(Rect(0, row, colcount, row)); if (col = 2) then if (row <> 0) then deleterow(row); end; procedure Register; begin RegisterComponents('Standard', [TPlayList]); end; end. |
Re: TPlaylist neue Komponente!
habe schon mal versucht das mit einem Record zu machen nur wie kann ich den veröffentlichen?
Delphi-Quellcode:
type
Tracks = record Title: String; time: String; path: String; end; |
Re: TPlaylist neue Komponente!
Erstelle eien Collection (Liste).
|
Re: TPlaylist neue Komponente!
Du kannst ihn doch über einen Property öffentlich machen
Delphi-Quellcode:
Gruss
:
public property Tracks[index:integer]:TTracks read GetTracks; : function TPlayList.GetTracks(index:integer):TTracks; begin Result:=StringGrid.Object[???]; // ich habe keine Ahnung wo // deine Trackinformationen gespeichert sind end; Thorsten |
Re: TPlaylist neue Komponente!
@mkinzler:
Was meinst du mit einer Liste? |
Re: TPlaylist neue Komponente!
Ich meinte in etwa das was omata beschrieben hat. Eine Indizierte Property (z.B. Items) mit der man auf die Elemente Zugreifen kann, welche intern in einem dyn. Array oder einer Liste (TList-Abkömmling) verwaltet wird.
|
Re: TPlaylist neue Komponente!
@omata
meinst du sowas?
Delphi-Quellcode:
Der Quelltext sieht jetzt so aus:
function TPlaylist.GetTracks (index: Integer): Tracks;
begin Tracks.Title := cells[1,index]; Tracks.time := cells[2, index]; Tracks.path := cells[4, index]; end;
Delphi-Quellcode:
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 Tracks = record Title: String; time: String; path: String; end; type TPlayList = class(TStringGrid) private { Private-Deklarationen } protected procedure Click; override; { Protected-Deklarationen } public public property Track[index:integer]:Tracks read GetTracks; constructor Create (AOwner: TComponent); override; { Public-Deklarationen } published procedure DeleteRow (RowNumber : Integer); procedure addFile (pfad, dauer, titel: String); function GetTracks(index:integer):Tracks; { Published-Deklarationen } end; procedure Register; implementation constructor TPlaylist.Create(AOwner: TComponent); begin inherited Create (AOwner); rowcount := 2; colcount := 3; fixedcols := 0; fixedrows := 1; defaultrowheight := 15; rowheights[0] := 18; Cells[0,0] := 'Title'; Cells[1,0] := 'Length'; Cells[2,0] := 'x'; ColWidths[0] := 200; colwidths[1] := 50; colwidths[2] := defaultrowheight; end; function TPlaylist.GetTracks (index: Integer): Tracks; begin Tracks.Title := cells[1,index]; Tracks.time := cells[2, index]; Tracks.path := cells[4, index]; end; procedure TPlaylist.addFile (pfad, dauer, titel: String); var i: Integer; mo: TInfos; begin rowcount := rowcount + 1; mo:=TInfos.create; mo.Filename:=''; Objects[rowcount-1,3]:=mo; cells[0, rowcount-1] := titel; cells[1, rowcount-1] := dauer; cells[2,rowcount-1] := 'x'; cells[3,rowcount-1] := pfad; Tracklist[rowcount].title := titel; Tracklist[rowcount].time := dauer; Tracklist[rowcount].path := pfad; end; procedure Tplaylist.DeleteRow(RowNumber : Integer); var i : Integer; begin Allerdings meckert er bei der property oben
Delphi-Quellcode:
Feld- oder Methodenbezeichner erwartet!
property Track[index:integer]:Tracks read GetTracks;
|
Re: TPlaylist neue Komponente!
So müsste es gehen...
Delphi-Quellcode:
Gruss
type
TTracks = record Title: String; time: String; path: String; end; : private { Private-Deklarationen } function GetTracks(index: Integer): TTracks; : public { Public-Deklarationen } property Track[index:integer]:TTracks read GetTracks; : function TPlaylist.GetTracks (index: Integer): TTracks; begin Result.Title:= cells[1, index]; Result.time := cells[2, index]; Result.path := cells[4, index]; end; Thorsten |
Re: TPlaylist neue Komponente!
Okay Danke!
Das funktioniert schon mal wunderbar. Nur werden ja jetzt Name, Dauer und der Pfad alle in einer Variablen ausgegeben. Ich würde aber gerne direkt darauf zugreifen können. Etwa so:
Delphi-Quellcode:
Soll den Titel zurückgeben, sprich das, was in Spalte eins in Reihe 1 steht!
playlist.track[1].title;
|
Re: TPlaylist neue Komponente!
Hi!
Das kannst du doch:
Delphi-Quellcode:
dummystring:=track[1].title;
Ciao, Frederic |
Alle Zeitangaben in WEZ +1. Es ist jetzt 01:05 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz