RandyBlackburn
Programmer
I'm using an old (Delphi I) component in turbo delphi, and I'm getting the error above. The code generating it is below... I got the error on both of the bolded lines.
I don't understand what's wrong. Are there components that perform these file copy/move functions in turbo delphi or somewhere else?
Any help will be appreciated
Randy
I don't understand what's wrong. Are there components that perform these file copy/move functions in turbo delphi or somewhere else?
Any help will be appreciated
Randy
Code:
procedure CopyFile(const FileName, DestName: TFileName);
var
CopyBuffer: Pointer; { buffer for copying }
TimeStamp, BytesCopied: Longint;
Source, Dest, SFOpenError, SFCreateError: Integer; { handles }
Destination: TFileName; { holder for expanded destination name }
const
ChunkSize: Longint = 8192; { copy in 8K chunks }
begin
Destination := ExpandFileName(DestName); { expand the destination path }
{if HasAttr(Destination, faDirectory) then { if destination is a directory... }
{Destination := Destination + '\' + ExtractFileName(FileName);}{ ...clone file name }
TimeStamp := FileAge(FileName); { get source's time stamp }
GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
try
Source := FileOpen(FileName, fmShareDenyNone{Write}); { open source file }
[b]if Source < 0 then raise EFOpenError.Create(FmtLoadStr(SFOpenError, [FileName]));[/b]
try
Dest := FileCreate(Destination); { create output file; overwrite existing }
[b] if Dest < 0 then raise EFCreateError.Create(FmtLoadStr(SFCreateError, [Destination]));[/b]
try
repeat
BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk }
if BytesCopied > 0 then { if we read anything... }
FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
until BytesCopied < ChunkSize; { until we run out of chunks }
finally
FileClose(Dest); { close the destination file }
{ SetFileTimeStamp(Destination, TimeStamp);} { clone source's time stamp }{!!!}
end;
finally
FileClose(Source); { close the source file }
end;
finally
FreeMem(CopyBuffer, ChunkSize); { free the buffer }
end;
end;