Function compfile (const F1, F2: string): Boolean; var ms1, MS2: tmemorystream; I, P: integer; B1, B2: byte; begin result: = false; if not (fileexists (F1) and fileexists (F2) Then exit; ms1: = tmemorystream. create; MS2: = tmemorystream. create; ms1.loadfromfile (F1); ms2.loadfromfile (F2); If ms1.size ms2.size then begin ms1.free; ms2.free; exit; end; Result: = true; randomize; for I: = 0 to 9 do begin P: = random (ms1.size); ms1.position: = P; ms2.position: = P; ms1.readbuffer (B1, 1); ms2.readbuffer (B2, 1 ); if B1 B2 then begin result: = false; break; end; ms1.free; ms2.free; end;
According to the guidance of "", make a slight modification. However, comparemem is not used to compare all the memory, and 10 samples may be faster.
function compfile (const F1, F2: string): Boolean; var fs1, fs2: tfilestream; Ms: tmemorystream; I, P: integer; B1, b2: byte; begin result: = false; if not (fileexists (F1) and fileexists (F2) Then exit; fs1: = tfilestream. create (F1, fmopenread); fs2: = tfilestream. create (F2, fmopenread); If fs1.size fs2.size then begin fs1.free; fs2.free; exit; end; Result: = true; randomize; for I: = 0 to 9 do begin P: = random (fs1.size); fs1.position: = P; fs2.position: = P; fs1.readbuffer (B1, 1); fs2.readbuffer (B2, 1); if b1 B2 then begin result: = false; break; end; fs1.free; fs2.free; end;