CRC
CRC (Cyclical Redundancy Check) is one of most important technique to ensure files
integrity while coping files, transfering files, backup, and even check files for
viruses.
This is an example of using CRC32.pas unit:
- Add CRC32 to Uses clause.
- Write this code:
Var
Err: integer;
CRC: integer;
begin
Err:= GetFileCRC('c:\command.com', CRC,
0, 0);
if Err <> 0 then
ShowMessage('Error while reading CRC code')
else
ShowMessage('File CRC code is: '+IntToStr(CRC));
end;
Very simple! isn't it ?
GetFileCRC function declared as:
Function GetFileCRC(FileName: string;
var CRCvalue: LongInt;
BytesFromStart,
BytesBeforEnd: LongInt): integer;
BytesFromStart and BytesBeforEnd enables you get file CRC code for any part of a
file. For example you can get file CRC without first 10 bytes:
GetFileCRC('c:\command.com', CRC, 10, 0);
If you want to get file CRC except last 4 bytes you can write:
GetFileCRC('c:\command.com', CRC, 0, 4);
CRC32.pas