(Gast)
n/a Beiträge
|
Re: Variable an Unit von Komponente übergeben?
5. Okt 2007, 17:42
Ok ist ziemlich lang:
Delphi-Quellcode:
{ Method UnSplit creates the original file from the split files. Name and
extension of the original file must be set in FileName property }
procedure TFileSplitter.UnSplit;
var
i: Integer;
Continue: Boolean;
sFileName: TFileName;
BytesRead, TotalRead: LongInt;
begin
if FileExists(FSplitFileName) then
begin
{ Make sure the filename is correct }
if FFileName = '' then
FFileName := ChangeFileExt(FSplitFileName, '.XXX');
{ Delete the resulting file if it exists }
if FileExists(FFileName) then
EraseFile(FFileName);
{ Prepare for writing to file }
FFile := TFileStream.Create(FFileName, fmCreate);
GetMem(FBuffer, FBufferSize);
try
i := 0;
sFileName := FSplitFileName;
{ Read files one by one and write to resulting file }
Continue := True;
Signature.NumberOfFiles := 0;
while Continue do
begin
if Assigned(FOnNeedDisk) then
FOnNeedDisk(Self, i + 1, Signature.NumberOfFiles, Continue);
if Continue then
begin
if FileExists(sFileName) then
begin
try
FSplitFile := TFileStream.Create(sFileName, fmOpenRead);
{ Read the signature from the first split file }
if i = 0 then
FSplitFile.Read(Signature, SizeOf(Signature));
TotalRead := 0;
while FSplitFile.Size <> FSplitFile.Position do
begin
BytesRead := FSplitFile.Read(FBuffer^, FBufferSize);
FFile.Write(FBuffer^, BytesRead);
TotalRead := TotalRead + BytesRead;
{ Call OnProgress event }
if Assigned(FOnProgress) then
FOnProgress(Self, (TotalRead * 100)
div FSplitFile.Size);
end;
finally
FSplitFile.Free;
end;
Inc(i);
sFileName := ChangeFileExt(sFileName, '.' +
StrZero(i, 3));
end
else
Continue := False;
end;
end;
finally
FreeMem(FBuffer);
FFile.Free;
end;
end
else
raise EFileError.Create('Input file '''
+ FSplitFileName + ''' does not exist.');
end;
|
|
Zitat
|