var stream: TMemoryStream; CrcValue,OldCrcValue: DWORD; exename: string; WriteBuf: array[0..3] of Byte; begin CRCValue := $FFFFFFFF; // 预设 WriteBuf[0]:= $00; WriteBuf[1]:= $00; WriteBuf[2]:= $00; WriteBuf[3]:= $00; exename:= application.ExeName; stream:= TMemoryStream.Create; stream.LoadFromFile(exename); // 载入自身exe文件到内存流 stream.Position:= 220; // 设定流的指针位置 stream.Read(OldCrcValue,4); // 读取原来的CRC值 stream.Position:= 220; // 设定流的指针位置,读取流时指针会自动相加 stream.Write(WriteBuf[0],4); // 将储存CRC值处用00补充,以便计算CRC值是否改过 CalcCRC32(stream.Memory,stream.Size,CrcValue); // 计算CRC CRCvalue := NOT CRCvalue; // 计算CRC FreeAndNil(stream); Edit1.Text:= IntToHex(OldCrcValue,8); Edit2.Text:= IntToHex(CrcValue,8); if CrcValue <> OldCrcValue then begin ShowMessage('文件已经被更改,程序退出!'); Application.Terminate; end else ShowMessage('文件校验正常!'); end;