Thema: Delphi read from multiple Files

Einzelnen Beitrag anzeigen

Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.184 Beiträge
 
Delphi 12 Athens
 
#3

Re: read from multiple Files

  Alt 25. Mär 2009, 19:06
Zitat von alzaimar:
Btw: In your code sample, you don't have to set any of the 'Size' or 'Position' properties. This is done by the constructor and the CopyFrom method, by setting the Size-parameter to 0.
Delphi-Quellcode:
Procedure Load(const AFilename: String);
var
  MS : TMemoryStream;
  FS : TFileStream;

begin
    if FileExists(AFilename) then
    begin
      MS := TMemoryStream.Create;
      try
        FS := TFileStream.Create(AFilename, fmOpenRead or fmShareDenyNone);
        try
          //FS.Position := 0;
          //MS.Position := 0;
          MS.CopyFrom(FS, FS.Size);
        finally
          FS.Free;
        end;
      finally
        MS.Free;
      end;
    end;
  end;
Zitat:
Delphi-Quellcode:
MyStringList:=TStringList.Create;
// string list contains no files. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
For i:=0 to MyStringList.count-1 do
  if FileExists(MyStringList[i]) then
Delphi-Quellcode:
MS := TMemoryStream.Create;
try
  For i:=0 to MyStringList.Count-1 do
    if FileExists(MyStringList[i]) then
    begin
      FS := TFileStream.Create(MyStringList[i], fmOpenRead or fmShareDenyNone);
      try
        MS.CopyFrom(FS, FS.Size);
      finally
        FS.Free;
      end;
    end;
  ...
finally
  MS.Free;
end;
$2B or not $2B
  Mit Zitat antworten Zitat