【3007137】<br>procedure Buttom1Click(Sender: TObject);<br>const<br> bSize = 1024; //read buffer size<br>var<br> hFile, rFile: THandle;<br> f: TextFile;<br> sFile: string;<br> iRead: Integer; //read bytes<br> iSize: Integer; //file size<br> Buffer: array [0..bSize] of Char;<br>begin<br> with TOpenDialog.Create(nil) do<br> begin<br> if Execute then<br> sFile := FileName;<br> Free;<br> end;<br><br> if not FileExists(sFile) then exit;<br><br> hFile := CreateFile(PChar(sFile),<br> GENERIC_READ,<br> FILE_SHARE_READ,<br> nil,<br> OPEN_EXISTING,<br> FILE_ATTRIBUTE_READONLY,<br> 0<br> );<br><br> iSize := GetFileSize(hFile, @iSize);<br><br> sFile := ChangeFileExt(sFile, '.bak');<br><br> rFile := FileCreate(sFile);<br><br> iRead := bSize;<br><br> while iRead > 0 do<br> begin<br> iRead := bSize;<br> if iSize < bSize then iRead := iSize;<br><br> ZeroMemory(@Buffer, iRead);<br> FileRead(hFile, Buffer, iRead);<br> FileWrite(rFile, Buffer, iRead);<br><br> Dec(iSize, iRead);<br> end;<br><br> CloseHandle(rFile);<br> CloseHandle(hFile);<br>end;