Einzelnen Beitrag anzeigen

Benutzerbild von Mackhack
Mackhack

Registriert seit: 29. Nov 2003
Ort: San Diego, CA/USA
1.446 Beiträge
 
Delphi 2006 Architect
 
#11

Re: AV mit TStringList-Methode Add()

  Alt 22. Jul 2006, 02:53
So hier ist meine Funktion. Ich weis nur leider nicht wie ich die Eintraege aus der TStringList nun in mein TestMemo bekomme und schaeme mich dafuer schonmal

Delphi-Quellcode:
function TFindFile.SearchFiles(aRoot: String; Mask: String = '*.xml'; Recursive : Boolean = False): TStringList;

  function IsLanguageFile(aFileName: String; aSearchString: String): Boolean;
  const
    MAX_BUFFER_SIZE = 10240;
  var
    FileStream: TFileStream;
    BufferSize: Integer;
    I: Integer;
    StrLength: Integer;
    Buffer: String;
    Found: Integer;
    ReadBytes: Integer;
  begin
    Result := False;

    if ( aSearchString = '' ) then
      Exit;

    aSearchString := AnsiLowerCase(aSearchString);
    FileStream := TFileStream.Create(aFileName, fmOpenRead or fmShareDenyWrite);
    try
      StrLength := Length(aSearchString);
      if ( FileStream.Size <= MAX_BUFFER_SIZE ) then
        BufferSize := FileStream.Size
      else
        BufferSize := MAX_BUFFER_SIZE * StrLength;
        SetLength(Buffer, BufferSize);
        repeat
          ReadBytes := FileStream.Read(Buffer[1], BufferSize);
          if ( ReadBytes = 0 ) then
            Exit;
          Buffer := AnsiLowerCase(Buffer);
          Found := 0;
          for I := 1 to ReadBytes - 1 do
          begin
            if ( BufferSize - (I - 1) >= StrLength ) then
            while (Buffer[I + Found] = aSearchString[Found + 1]) do
            begin
              Inc(Found);
              if ( Found = StrLength ) then
              begin
                Result := True;
                Exit;
              end;
            end;
          end;
        until ( FileStream.Position <= FileStream.Size );
    finally
      FileStream.Free;
      SetLength(Buffer, 0);
    end;
  end;

var
  wfd : TWin32FindData;
  hFile : THandle;
begin
  if ( AnsiLastChar(aRoot)^ <> '\' ) then
    aRoot := aRoot + '\';
  if Recursive then
  begin
    hFile := FindFirstFile(PChar(aRoot + '*.xml'), wfd);
    if ( hFile <> INVALID_HANDLE_VALUE ) then
    try
      repeat
        if ( wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY = FILE_ATTRIBUTE_DIRECTORY ) then
          if ( (String(wfd.cFileName) <> '.') and (String(wfd.cFileName) <> '..') ) then
            SearchFiles(aRoot + wfd.cFileName, Mask, Recursive);
      until FindNextFile(hFile, wfd) = False;
    finally
      Windows.FindClose(hFile);
    end;
  end;
  hFile := FindFirstFile(PChar(aRoot + '*.xml'), wfd);
  if ( hFile <> INVALID_HANDLE_VALUE ) then
  Result := TStringList.Create;
  try
    repeat
      if (wfd.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY <> FILE_ATTRIBUTE_DIRECTORY ) then
        if ( IsLanguageFile(aRoot + wfd.cFileName, '<Languages>') ) then
          Result.Add(aRoot + wfd.cFileName);
    until FindNextFile(hFile, wfd) = False;
  finally
    Windows.FindClose(hFile);
  end;
end;
Jedoch weis ich immer noch net wo ich das Files.Free hinparken muss!
Um etwas Neues zu schaffen muss man seine Ohren vor den Nein-sagern verschliessen um seinen Geist öffnen zu können.
(George Lukas)
  Mit Zitat antworten Zitat