描述: 首先在临时文件夹中有一个数据库文件(access),用户的操作都是保存在此文件中。 当用户第一次保存的时候,就将该临时文件,通过copyfile保存到指定位置。用户以后的操作还是在临时文件中进行的。如果再次保存的话,则再通过copyfile 将临时文件覆盖指定位置的文件。 判断是否需要保存的方式(临时文件和保存的文件是否一致,),现在用的是crc方式。但是很奇怪:
第一次通过copyfile 复制临时文件到指定目录。(文件出现在指定位置,并且和临时文件一致) 此时去判断文件是否相同的话,结果却是:文件不一致(实际应该是相同的) 再将临时文件copyfile一次后,结果:相同文件。
以后的每一次操作都正常了。 也就是说第一次保存需要两次copyfile后,才能得出文件相同的情况。 不知道这是不是windows本身文件系统的问题呢,还是CRC操作的问题。【crc判断以后的每次都正常了,就是第一次是有问题的。不应该是CRC的问题】
功能:接收文件名,返回文件的CRC值
-----------------------------------------------------------------------------}
function TDBIsSame.GetFileCRC(AFileName: string): string;
var
iLoopIndex, jLoopIndex: Integer; //循环下标
nCRCTableElement, nCRC, nXorCRC: Integer;
arrCRCTable: array[0..255] of Integer;
oMemoryStream: TMemoryStream; //流对象
pMemory: PChar;
nAndCRC: Byte;
begin
Result := '';
for iLoopIndex := 0 to 255 do
begin
nCRCTableElement := iLoopIndex;
for jLoopIndex := 0 to 7 do
begin
if Boolean(nCRCTableElement and 1) then
nCRCTableElement := Cardinal(nCRCTableElement shr 1) xor $EDB88320
else
nCRCTableElement := nCRCTableElement shr 1;
end;
arrCRCTable[iLoopIndex] := nCRCTableElement;
end;
oMemoryStream := TMemoryStream.Create;
try
oMemoryStream.LoadFromFile(AFileName);
if oMemoryStream.Size <= 0 then
begin
oMemoryStream.Free;
Exit;
end;
pMemory := oMemoryStream.Memory;
nCRC := -1;
for iLoopIndex := 0 to oMemoryStream.Size - 1 do
begin
nAndCRC := nCRC and $000000FF;
nXorCRC := PByte(@pMemory[iLoopIndex])^ xor nAndCRC;
nCRC := nCRC shr 8;
nCRC := nCRC xor arrCRCTable[nXorCRC];
end;
nCRC := not nCRC;
Result := Format('%x', [nCRC]);
finally
FreeAndNil(oMemoryStream);
end;
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货