Pastebin
Paste #2474: pascal write, runerror 1784
< previous paste - next paste>
Pasted by zaher
procedure Log(s:string); begin end; procedure WriteFile(Filename: String; BufferSize: longint); var //Buffer: Array of Byte; Buffer: PByte; BytesWritten, i, j: longint; StartTime, EndTime, TmpTime, TmpTime2, Elapsed: integer; WriteTime, WriteSpeed: Double; StatusLine : String; OutFile: File; tmp: Word; doWrite: Boolean; begin Log('WriteFile("'+Filename+'", '+IntToStr(BufferSize)+')'); StartTime := GetTickCount(); BytesWritten:=0; //SetLength(Buffer, BufferSize); Buffer := AllocMem(SizeOf(Byte) * BufferSize); // Initialize buffer with random bytes Randomize; Log('Initializing buffer with random bytes...'); for j:=0 to BufferSize do begin Buffer[j] := Random(256); end; Log('Initialized buf[0..' + IntToStr(j) + ']'); // Write the file Log('Opening "' + Filename + '" for writing...'); Assign(OutFile, Filename); Rewrite(OutFile, BufferSize); Log('File opened...'); doWrite := true; try // Form1.ProgressBar1.Position:=0; // Form1.ProgressBar1.Max:=Round((DiskFree(0) - BufferSize * 2 ) / 1024 / 1024); i := 0; While ( (doWrite = True ) and (DiskFree(0) > BufferSize * 2) ) do Begin Inc(i); If doWrite Then Begin TmpTime := GetTickCount64(); BlockWrite(OutFile, Buffer, 1, tmp); FlushThread; BytesWritten:= BytesWritten + BufferSize; Elapsed := GetTickCount() - StartTime; try //Form1.StatusBar1.Panels[2].Text := 'Speed: ' + FormatFloat('0.00', (byteswritten / 1024/1024) / (elapsed / 1000)) + ' mb/s'; Except end; tmptime2 := GetTickCount64(); StatusLine:=''; StatusLine:=StatusLine + ' I=' + IntToStr(i); StatusLine:=StatusLine + ' BytesWritten='+ IntToStr(BytesWritten); StatusLine:=StatusLine + ' CycleTime=' + IntToStr(tmptime2 - tmptime); Log(StatusLine); Application.ProcessMessages; end else begin Log('Aborting!'); end; Application.ProcessMessages; end; Log('Done!'); finally // Close the file handle Log('Closing file handle.'); Close(OutFile); //Free; end; EndTime:=GetTickCount(); WriteTime:=(endtime-starttime)/1000; WriteSpeed:=BytesWritten/1024/1024/writetime; if doWrite then else Log('Write aborted'); Freemem(Buffer); end; { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin WriteFile('c:\1.txt', 1024*1024); end;
New Paste
Go to most recent paste.