Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 10.07.05 11:23 
Ich brauch ne funktion um alle Dateien einer bestimmten Dateiendung in einer listbox angezeigt bekomme. Hab im netz schon gefunden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button2Click(Sender: TObject);
var
  s, path: string;
begin
  path:=extractfilepath(application.exename)+'*.thm'#0;
  s := path;
  ListBox1.Perform(LB_DIR, DDL_READWRITE, LongInt(@s[1]));
end;


ausblenden 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:
//Oder mit dieser Function
function ReadDir(Path, Mask: string; ShowPath: boolean): TStringlist;
var SRec: TSearchRec;
  SL: TStringList;
begin
  SL := TStringList.Create;
  FindFirst(Path + Mask, not faDirectory, SRec);
  if ShowPath then
    SL.Add(Path + SRec.Name)
  else
    SL.Add(SRec.Name);
  while FindNext(SRec) = 0 do
    if ShowPath then
      SL.Add(Path + SRec.Name)
    else
      SL.Add(SRec.Name);
  FindClose(SRec);
  Result := SL;
end;



//Aufruf
procedure TForm1.Button2Click(Sender: TObject);
var
  path : string;
begin
  path:=extractfilepath(application.exename)+'Themen\'+Edit1.Text+'\';
  ListBox1.Items:=ReadDir(path,'*.THM',false);
end;



Aber in meiner listbox ist nix erschienen. Könnt ihr mir weiterhelfen?

Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
pupsii
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 10.07.05 11:48 
Dein erstes Beispiel:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
procedure TForm1.Button2Click(Sender: TObject);
var
s, path: string;
begin
path:=extractfilepath(application.exename)+'*.thm';
s := path;
ListBox1.Perform(LB_DIR, DDL_READWRITE, LongInt(@s[1]));
end;

Dieses Beispiel funktioniert bei mir. Hast du auch drauf geschaut, dass im selben Ordner der .exe-Datei diese .thm Dateien sind? Vielleicht hast du dich auch verschrieben und es sind .htm Dateien. Könnte natürlich ein Grund sein, dass nichts angezeigt wird.


Zuletzt bearbeitet von pupsii am So 10.07.05 11:59, insgesamt 2-mal bearbeitet
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: So 10.07.05 11:53 
Könntet ihr nicht BITTE statt Code- oder garkeinen Tags DELPHI tags nehmen? da is das so viel entspannter für die augen.
Bevor ihr fragt: [delphi]blubber; code.schreibHier(hin);[/delphi]

user profile iconpupsii hat folgendes geschrieben:
Bei deinem letzten Beispiel hast du folgenden Code:
ausblenden Quelltext
1:
ListBox1.Items:=ReadDir(path,'*.THM',false);					

ReadDir findet er bei mir nicht, oder hast du eine spezielle Unit eingebunden?

Schau dir mal die Funktion an, die er geschrieben hat:
Zitat:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
function ReadDir(Path, Mask: string; ShowPath: boolean): TStringlist; 
var SRec: TSearchRec; 
SL: TStringList; 
begin 
SL := TStringList.Create; 
FindFirst(Path + Mask, not faDirectory, SRec); 
if ShowPath then 
SL.Add(Path + SRec.Name) 
else 
SL.Add(SRec.Name); 
while FindNext(SRec) = 0 do 
if ShowPath then 
SL.Add(Path + SRec.Name) 
else 
SL.Add(SRec.Name); 
FindClose(SRec); 
Result := SL; 
end;


Moderiert von user profile iconraziel: Überflüssiges Zitat des ersten Postings entfernt.

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
pupsii
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 10.07.05 11:58 
Hoppla.. ganz übersehen..

Trotzdem müsste das erste Beispiel doch auch funktionieren.