Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi TStrings Liste (https://www.delphipraxis.net/110301-tstrings-liste.html)

tmrxxoja 16. Mär 2008 12:54


TStrings Liste
 
moin moin

ich brauch mal eure hilfe mit TStrings

also ich habe ein Grid "Grid" und eine String liste "aList : TStrings;"

hmm wie bekomme ich die daten aus der liste nun in das Grid rein ?

gut eine schleife durchlaufen

Delphi-Quellcode:
 
  inc(nBild);
  Grid.RowCount := Grid.RowCount+1;
  Grid.Cells[0,nBild] := 'test1';
das ist nicht das problem aber wie bekomme ich die daten aus den TStrings raus?


Delphi-Quellcode:
  for n := 0 to aList.Count do begin
    inc(nBild);
    Grid.RowCount := Grid.RowCount+1;

    Grid.Cells[0,nBild] := 'test1';
    Grid.Cells[1,nBild] := aList[nBild];
    Grid.Cells[2,nBild] := 'test3';
  end;

Fussball-Robby 16. Mär 2008 12:59

Re: TStrings Liste
 
alist[index]

Mfg

mkinzler 16. Mär 2008 12:59

Re: TStrings Liste
 
Was steht genau in der Liste? Zeilen/Spalten?

tmrxxoja 16. Mär 2008 13:04

Re: TStrings Liste
 
keine spalten

eigentlich nur Pfad angaben

Delphi-Quellcode:
unit Main;

interface

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

type
  TForm1 = class(TForm)
    Grid: TStringGrid;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    nBild : integer;
  end;

procedure FileList(const APath, AExt: string; ARecurse: Boolean; AList: TStrings);

var
  Form1: TForm1;

implementation

{$R *.dfm}

//******************************************************************************
procedure TForm1.Button1Click(Sender: TObject);
var cPfad : string;
    aList : TStrings;
        n : integer;
begin

  cPfad := 'c:/test/';
  FileList(cPfad, '*.jpg', True, aList);

  for n := 0 to aList.Count do begin
    inc(nBild);
    Grid.RowCount := Grid.RowCount+1;

    Grid.Cells[0,nBild] := 'test1';
    Grid.Cells[1,nBild] := aList[nBild];
    Grid.Cells[2,nBild] := 'test3';
  end;

end;

//******************************************************************************

procedure FileList(const APath, AExt: string; ARecurse: Boolean; AList: TStrings);
var
  F   : TSearchRec;
  Path : string;
begin
  Path := IncludeTrailingPathDelimiter(APath); // nur für Delphi 4 und höher!
  if (ARecurse) and
    (FindFirst(Path + '*.*', faAnyFile, F) = 0) then
  try
    repeat
      if (F.Name <> '.') and (F.Name <> '..') and
        ((F.Attr and faDirectory) = faDirectory) then
        FileList(Path + F.Name, AExt, ARecurse, AList);
    until FindNext(F) <> 0;
  finally
    FindClose(F);
  end;
  if FindFirst(Path + AExt, faAnyFile, F) = 0 then
  try
    repeat
      if (F.Name <> '.') and (F.Name <> '..') and
        ((F.Attr and faDirectory) <> faDirectory) then
        AList.Add(Path + F.Name);
    until FindNext(F) <> 0;
  finally
    FindClose(F);
  end;
end;

//******************************************************************************

procedure TForm1.FormCreate(Sender: TObject);
begin
  nBild := 0;

  Grid.Cells[0,0]:= 'Bildname';
  Grid.Cells[1,0]:= 'Pfad';
  Grid.Cells[2,0]:= 'Erstellungdatum';


end;

end.
so sieht zur zeit mein programm aus

Fussball-Robby 16. Mär 2008 13:05

Re: TStrings Liste
 
Zitat:

Zitat von Fussball-Robby
alist[index]


mkinzler 16. Mär 2008 13:06

Re: TStrings Liste
 
Also alles in einer Zeile?

Delphi-Quellcode:
Grid.Rows[0].Assign( Alist);

tmrxxoja 16. Mär 2008 13:20

Re: TStrings Liste
 
Hmm hab noch ein Fehler drin

Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var cPfad : string;
    aListe : TStrings;
        n : integer;
begin

  cPfad := 'c:/test/';
  FileList(cPfad, '*.jpg', True, aListe);

  for n := 0 to aListe.Count do begin
    inc(nBild);
    Grid.RowCount := Grid.RowCount+1;

    Grid.Cells[0,nBild] := 'test1';
    Grid.Rows[1].Assign(aListe);
    Grid.Cells[2,nBild] := 'test3';
  end;

end;
die meldung

Zitat:

Variable "aListe" ist möglicherweise nicht initialisiert worden
hmm aber ist sie doch oder ??

aListe : TStrings;

oder irre ich mich ?

Fussball-Robby 16. Mär 2008 13:22

Re: TStrings Liste
 
da fehlt noch ein
Delphi-Quellcode:
aliste:=TStringList.Create;
Mfg

mkinzler 16. Mär 2008 13:23

Re: TStrings Liste
 
Wie sieht FileList() aus?
Delphi-Quellcode:
aListe : TStrings;
erzeugt nur einen Referenzvariable aber kein Objekt.

Delphi-Quellcode:
aListe := TStringList.Create;
Warum die Schleife?

Fussball-Robby 16. Mär 2008 13:25

Re: TStrings Liste
 
Zitat:

Zitat von mkinzler
Wie sieht FileList() aus?

Hat er oben schon gepostet

Mfg


Alle Zeitangaben in WEZ +1. Es ist jetzt 02:51 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