Советы по Delphi



         

Быстрая обработка файла


typeTByteSet = set of byte ;
procedure ProcessFile( const InFileName,OutFileName: string; Valid: TByteSet ) ;varInFile, OutFile : file ;InBuf, OutBuf : PByteArray ;InPos, OutPos : word ;BytesRead : word ;beginOutBuf := NIL ;New( InBuf ) ;tryNew( OutBuf ) ;AssignFile( InFile, InFileName ) ;AssignFile( OutFile, OutFileName ) ;Reset( InFile, 1 ) ;Rewrite( OutFile, 1 ) ;repeatBlockread( InFile, InBuf^, SizeOf( InBuf^ ), BytesRead ) ;OutPos := 0 ;for InPos := 0 to BytesRead - 1 do beginif InBuf^[ InPos ] in Valid then begininc( OutPos ) ;end ;end ;if OutPos > 0 then BlockWrite( OutFile, OutBuf^, OutPos ) ;until BytesRead <> SizeOf( InBuf^ ) ;CloseFile( InFile ) ;CloseFile( OutFile ) ;finallyif OutBuf <> NIL then Dispose( OutBuf ) ;Dispose( InBuf ) ;end ;end;

Применять это можно приблизительно так:

ProcessFile( 'SOURCE.RAW', 'NEW.RAW', [ 10, 13, 32..255 ] ) ;

- Mike Scott [000865]




Содержание  Назад  Вперед