Einzelnen Beitrag anzeigen

marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#2

Re: schnellere Procedure gesucht

  Alt 19. Dez 2005, 18:12
Mein Code sieht anders aus: klick

Grüße vom marabu

EDIT: Angepasst an die verschiedenen Bedürfnisse aus deinen anderen threads kann das dann (ungetestet) so aussehen:

Delphi-Quellcode:
unit Unit1;

interface

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

type
  TDemoForm = class(TForm)
    ListBox: TListBox;
    FindButton: TButton;
    CancelButton: TButton;
    procedure FindButtonClick(Sender: TObject);
    procedure CancelButtonClick(Sender: TObject);
  private
    CanceledByUser: boolean;
    procedure AllFilesWithExtension(folder: string; s, ext: TStrings);
  end;

var
  DemoForm: TDemoForm;

implementation

{$R *.dfm}

procedure TDemoForm.AllFilesWithExtension(folder: string; s, ext: TStrings);
var
  sr: TSearchRec;
begin
  folder := IncludeTrailingPathDelimiter(folder);
  if FindFirst(folder + '*.*', faAnyFile, sr) = 0 then
  try
    repeat
      Application.ProcessMessages;
      if (sr.Name = '.') or (sr.Name = '..') then
        Continue
      else
      if (sr.Attr and faDirectory) = faDirectory then
        AllFilesWithExtension(folder + sr.Name, s, ext)
      else
      begin
        if ext.IndexOf(ExtractFileExt(sr.Name)) <> -1 then
          s.Add(folder + sr.Name);
      end;
    until CanceledByUser or (FindNext(sr) <> 0);
  finally
    FindClose(sr);
  end;
end;

procedure TDemoForm.FindButtonClick(Sender: TObject);
var
  ext: TStringList;
begin
  ext := TStringList.Create;
  ext.Sorted := true;
  ext.Add('.mp3');
  ext.Add('.wav');
  ListBox.Clear;
  CanceledByUser := false;
  AllFilesWithExtension('C:\', ListBox.Items, ext);
  ext.Free;
end;

procedure TDemoForm.CancelButtonClick(Sender: TObject);
begin
  CanceledByUser := true;
end;

end.
  Mit Zitat antworten Zitat