Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi TPlaylist neue Komponente! (https://www.delphipraxis.net/75191-tplaylist-neue-komponente.html)

smepal 15. Aug 2006 17:18


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:
playlist.tracks[1].path
playlist.tracks[1].name
playlist.tracks[1].time
Wie kann ich das realisieren?

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.

smepal 15. Aug 2006 18:31

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;

mkinzler 15. Aug 2006 18:34

Re: TPlaylist neue Komponente!
 
Erstelle eien Collection (Liste).

omata 15. Aug 2006 18:36

Re: TPlaylist neue Komponente!
 
Du kannst ihn doch über einen Property öffentlich machen

Delphi-Quellcode:
:
  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;
Gruss
Thorsten

smepal 15. Aug 2006 18:54

Re: TPlaylist neue Komponente!
 
@mkinzler:
Was meinst du mit einer Liste?

mkinzler 15. Aug 2006 18:59

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.

smepal 15. Aug 2006 19:03

Re: TPlaylist neue Komponente!
 
@omata
meinst du sowas?
Delphi-Quellcode:
function TPlaylist.GetTracks (index: Integer): Tracks;
begin
Tracks.Title := cells[1,index];
Tracks.time := cells[2, index];
Tracks.path := cells[4, index];

end;
Der Quelltext sieht jetzt so aus:
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:
property Track[index:integer]:Tracks read GetTracks;
Feld- oder Methodenbezeichner erwartet!

omata 15. Aug 2006 19:15

Re: TPlaylist neue Komponente!
 
So müsste es gehen...

Delphi-Quellcode:
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;
Gruss
Thorsten

smepal 15. Aug 2006 19:37

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:
playlist.track[1].title;
Soll den Titel zurückgeben, sprich das, was in Spalte eins in Reihe 1 steht!

fkerber 15. Aug 2006 19:41

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 03:52 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz