Autor Beitrag
mcbrunox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 92



BeitragVerfasst: So 01.09.02 13:14 
Ich habe hier eine Routine zum Einlesen von Dateien.
Meine Frage nun...Wie sichere ich die Daten in ein Array und nicht in eine Listbox
ausblenden 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:
procedure listfiles(dir, mask: string);
var
  rec:   TSearchRec;
  found: Integer;
begin
  if dir[Length(dir)] <> '\' then dir := dir + '\';
  found := findfirst(dir + mask, faAnyFile, rec);
  try
    while found = 0 do
    begin
      Application.ProcessMessages;
      if (rec.Attr and faDirectory <= 0) then
        Form1.ListBox1.Items.Add(dir + rec.Name);
      found := findnext(rec);
    end;
  finally
    findclose(rec);
  end;
  found := findfirst(dir + '*.*', faAnyFile, rec);
  try
    while found = 0 do
    begin
      if (rec.Attr and faDirectory > 0) and (rec.Name[1] <> '.') then
        ListFiles(dir + rec.Name, mask);
      found := findnext(rec);
    end;
  finally
    findclose(rec);
  end;
end;
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: So 01.09.02 13:32 
warum ein array? nimm doch eine Stringlist. Ich finde Stringlist sehr praktisch und wenn ein array wirklich erforderlich ist, dann machste einfach ein array of string. Dann musste mit SetLength die länge des Arrays anpassen und die datein reinschreiben. Such einfach mal in der Hilfe nach SetLength. Da dürfteste fündig werden. wenn nicht, dann poste nochmal :mrgreen:

_________________
Viele Grüße
Jakob
mcbrunox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 92



BeitragVerfasst: So 01.09.02 13:57 
da ich ein kompletter newbie,könntest du mir das anhand des codes erklären ?
Stringlist ist das eine komponente ?
XPert
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 129

Windows 98/00/Me/XP
D6 Pers
BeitragVerfasst: So 01.09.02 14:04 
müsste dem namen nach eine komponente sein! ich wüsste auch mal gerne was das ist, denn das kann keine standart-komponente sein.... (zumindest bin ich so blind das ich sie net sehen kann *g*)

_________________
MfG Fabian Schweers :lol:
bis11
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1247
Erhaltene Danke: 2

Apple Mac OSX 10.11

BeitragVerfasst: So 01.09.02 19:30 
Müsste ungefähr so funktionieren : (ungetestet)

ausblenden volle Höhe 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:
procedure listfiles(dir, mask: string); 
var 
  Listbox1: TStringList;
  rec: TSearchRec; 
  found: Integer; 
begin 
  Listbox1 := TStringList.Create;
  Listbox1.Clear;
  if dir[Length(dir)] <> '\' then dir := dir + '\'; 
  found := findfirst(dir + mask, faAnyFile, rec); 
  try 
    while found = 0 do begin 
      Application.ProcessMessages; 
      if (rec.Attr and faDirectory <= 0) then 
        Form1.ListBox1.Items.Add(dir + rec.Name); 
      found := findnext(rec); 
    end; 
  finally 
    findclose(rec); 
  end; 
  found := findfirst(dir + '*.*', faAnyFile, rec); 
  try 
    while found = 0 do begin 
      if (rec.Attr and faDirectory > 0) and (rec.Name[1] <> '.') then 
        ListFiles(dir + rec.Name, mask); 
      found := findnext(rec); 
    end; 
  finally 
    findclose(rec); 
  end; 
end;


Du solltest dafür Deine Kompo Listbox von der Form entfernen oder das Wort Listbox1 durch ein anderes ersetzen.
DeCodeGuru
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1333
Erhaltene Danke: 1

Arch Linux
Eclipse
BeitragVerfasst: So 01.09.02 19:57 
Hier ist eine "array"-Variante. Der Code wurde von mir in dem Forumeingabeforumlar umgeschrieben --> nicht getestet. Wenn Fehler auftreten bitte melden :mrgreen:
ausblenden volle Höhe 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:
procedure listfiles(dir, mask: string);
var
  Strings: array of String;
  rec: TSearchRec;
  found, anzahl: Integer;
begin
  anzahl := 0;
  if dir[Length(dir)] <> '\' then dir := dir + '\';
  found := findfirst(dir + mask, faAnyFile, rec);
  try
    while found = 0 do begin
      Application.ProcessMessages;
      if (rec.Attr and faDirectory <= 0) then
        SetLength(Strings,anzahl +1);
        Inc(anzahl);
        Strings[anzahl] := dir + rec.Name;
      found := findnext(rec);
    end;
  finally
    findclose(rec);
  end;
  found := findfirst(dir + '*.*', faAnyFile, rec);
  try
    while found = 0 do begin
      if (rec.Attr and faDirectory > 0) and (rec.Name[1] <> '.') then
        ListFiles(dir + rec.Name, mask);
      found := findnext(rec);
    end;
  finally
    findclose(rec);
  end;
end;

_________________
Viele Grüße
Jakob
aogwaba
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 109



BeitragVerfasst: So 01.09.02 20:13 
zum Einlesen der Filenamen kannst du auch eine TDirectoryListBox benutzen.