Autor Beitrag
BM_90
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: Fr 14.12.07 16:09 
Ich hab eine procedure mit der man datein eines bestimmten typs suchen und im einer listbox ausgeben kann.
das problem ist nur, dass der rechner zwar sucht, aber nichts ausgibt.
ich hab aber leider keine ahnung wo mein fehler ist...


ausblenden volle Höhe 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:
31:
32:
33:
34:
35:
36:
37:
38:
39:
  private
    { Private-Deklarationen }
    procedure suche(ext: str3; pfad: string);
...


procedure tform2.suche(ext: str3; pfad: string);
var sr:tsearchrec;
    r:integer;
begin
  r:=findfirst(pfad+'\*.*', faanyfile, sr);
  while r=0 do
  begin
    if copy(sr.Name, 11) <> '.' then
    begin
      if (sr.Attr <>0and (fadirectory <>0then
        suche(ext, pfad + '\' + sr.name)
      else
        if system.Copy(sr.Name, pos('.', sr.Name),4) = '.' + ext then
           form2.ListBox1.Items.Add(pfad + '\' + sr.Name);
    end;
    application.ProcessMessages;
    r:=findnext(sr);
  end;
  findclose(sr);
end;

procedure TForm2.Button3Click(Sender: TObject);
begin
if length(form2.edit1.Text) > 3 then
  begin
    showmessage('Bitte maximal 3 Zeichen für die Erweiterung angeben!');
    exit;
  end;
form2.button3.Enabled:=false;
form2.ListBox1.Clear;
suche(form2.edit1.Text, form2.drivecombobox1.Drive + ':');
form2.button3.Enabled:=true;
end;


Moderiert von user profile iconGausi: Delphi-Tags hinzugefügt
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Fr 14.12.07 16:34 
Deine "Suchfunktion" ist falsch (muss was mit der Schleife zu tun haben, normalerweise verwendet man eine repeat-until-Schleife). Verwende am Besten diese Funktion hier:
www.dsdt.info/tipps/?id=134

Und dann kannste doch direkt nach '*.' + ext suchen. Dann brauchste kein Copy oder ähnliches ;-)

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Atreyu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 137


Delphi 7 Enterprise
BeitragVerfasst: Mo 17.12.07 12:36 
Er hat ja eine Schleife drin. Oben, mit while.

Was den Link betrifft, den wollte ich auch gerade heraussuchen. Das funktioniert wirklich gut.
BM_90 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: Mo 17.12.07 14:58 
Vielen dank leute!!!
hat mir auf jedn fall geholfn. jetz hab ich nur das problem, dass ich nich weiß, wie ich den spaß mit der drivecombobox und dem dateityp auf die reihe kriege. egal was ich machem, mein delphi meckert. brsuche den spaß, um meinen rechner nach bildern zu durchsuchn un muss die sachn, die er mir als suchergebnis anzeigt markiern un in meim programm öffnen könn. das haut nich hin, stehe irgendwie auf der leitung...

vieln dank nochmal, wart mir ne große hilfe
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 17.12.07 16:58 
user profile iconAtreyu hat folgendes geschrieben:
Er hat ja eine Schleife drin. Oben, mit while.

Ja eben. Bin mir nicht sicher, ob es eine repeat-until-Schleife sein muss, damit die Bedinung erst am Ende geprüft wird.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Atreyu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 137


Delphi 7 Enterprise
BeitragVerfasst: Mo 17.12.07 17:26 
Ich glaube, vom Prinzip her ist die Schleife im Beispiel nicht verkehrt.
Am Ende wird ja das Ergebnis der Suche in r gesteckt, dann springt er zum Kopf der Schgleife zurück und überprüft r. Ist also eine Reine Aufbausache.
Wird wohl was anderes nicht funktioniert haben. Oder ich irre mich...
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 17.12.07 17:35 
Beispiel:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
r := 0;
while (r <> 0do
  r := 1;

r := 0
repeat
  r := 1;
until r = 0;


Mal davon abgesehen, dass diese Schleifen sinnlos sind, aber die obere wird nie aufgerufen, wärend die untere mindestens 1x durchlaufen wird. Könnte also sein, dass bei BM_90 die Schleife nie aufgerufen wird.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
BM_90 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: Mo 17.12.07 17:37 
ich werde da jetzt leider nicht so ganz schlsu drauß, aber naja, stell mich meistens ein bisschen doof an...
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 17.12.07 17:39 
War auch nicht speziell an dich, sondern an Atreyu. Ist eh besser, wenn du die verlinkte Funktion verwendest und bei weiteren Fragen einfach einen neuen Thread eröffnest.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
BM_90 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: Di 18.12.07 11:26 
Moin!
Ich bräuchte deswegen nochmal Hilfe. Die Dateisuche, haut zwar einwandfrei hin, aber ich möchte den Suchpfad durch eine DriveComboBox angeben. Das ist zwar eigentlich ein nicht allzu großes Problem, aber irgendwie haut das nicht hin. Wenn ich die DriveComboBox benutze, gibt mein Programm die Dateinamen nicht mehr aus. Außerdem möchte ich gerne noch per ComboBox den zu suchenden Dateitypen angeben.
Ich arbeite mit Delphi in dem Ausmaß leider noch nicht allzu lange. Ich glaube langsam, ich habe mir etwas zu viel vorgenommen...
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Di 18.12.07 15:34 
user profile iconBM_90 hat folgendes geschrieben:
Das ist zwar eigentlich ein nicht allzu großes Problem, aber irgendwie haut das nicht hin.

Zeig mal wie du den Suchpfad aus der DriveComboBox an deine Funktion übergibst.

_________________
Ein Nutzer der Ecke ;-)
BM_90 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: Di 18.12.07 17:40 
user profile iconMartin1966 hat folgendes geschrieben:
Zeig mal wie du den Suchpfad aus der DriveComboBox an deine Funktion übergibst.


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TForm2.Button3Click(Sender: TObject);
begin
  GetFilesInDirectory(inttostr(form2.DriveComboBox1.ItemIndex), '*.*', Listbox1.Items, true, True);
end;


Moderiert von user profile iconTino: Delphi-Tags hinzugefügt
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Mi 19.12.07 14:04 
Zuerst mal: benutze doch bitte die Delphi-Tags um deinen Sourcecode hier besser darzustellen. ;-) Danke!

Ich gehe davon aus das der erste Parameter von GetFilesInDirectory das Start-Verzeichnis sein soll, oder?

Hast du dir mal angeschaut was inttostr(form2.DriveComboBox1.ItemIndex) zurückliefert? Ich denke das ist kein korrekter Wert um diesen an GetFilesInDirectory zu übergeben. ;-)

Lg, Martin

_________________
Ein Nutzer der Ecke ;-)
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Mi 19.12.07 14:09 
Ist einfach, war bei meinem Suchprogramm auch der Fehler:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
procedure tform2.suche(ext: str3; pfad: string);
var sr:tsearchrec;
    r:integer;
begin
  r:=findfirst(pfad+'\*.*', faanyfile, sr);
  while r=0 do
  begin
    if copy(sr.Name, 11) <> '.' then
    begin
      if (sr.Attr and faDirectory) <> 0 then
        suche(ext, pfad + '\' + sr.name)
      else
        if system.Copy(sr.Name, pos('.', sr.Name),4) = '.' + ext then
           form2.ListBox1.Items.Add(pfad + '\' + sr.Name);
    end;
    application.ProcessMessages;
    r:=findnext(sr);
  end;
  findclose(sr);
end;


edit: Oh, darum gehts ja gar nicht mehr...

_________________
1405006117752879898543142606244511569936384000000000.
BM_90 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: Mi 19.12.07 14:43 
Vielen Dank, hat aber nix gebracht, haut immernoch nicht hin.
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Mi 19.12.07 15:20 
Schau mal hier:
www.delphi-forum.de/...hprogramm_73739.html
Das ist mein Suchprogramm, da funktioniert es...

_________________
1405006117752879898543142606244511569936384000000000.
Martin1966
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1068

Win 2000, Win XP
Delphi 7, Delphi 2005
BeitragVerfasst: Mi 19.12.07 15:28 
@BM_90: Hast du meinen Hinweis überlesen?

_________________
Ein Nutzer der Ecke ;-)
BM_90 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 49



BeitragVerfasst: Do 03.01.08 16:46 
Äh, nee hab ich nicht. Ich hab nur nicht so ganz verstanden, was du mir sagen wolltest. War außerdem schon lange nicht mehr im Netz und hab es dann irgendwie vergessen... Sorry