比较两个文件是否一样

比较两个文件是否一样

function AreSameFiles(File1 : TFileName ; File2 : TFileName): Boolean;
var
  MS1 : TMemoryStream;
  MS2 : TMemoryStream;
begin
  Result :
= false;
  MS1 :
= TMemoryStream.Create;
  
try
    MS1.LoadFromFile(File1);
    MS2 :
= TMemoryStream.Create;
    Try
      MS2.LoadFromFile(File2);
      
if MS1.Size=MS2.Size then
      
begin
        Result :
= CompareMem(MS1.Memory , MS2.Memory , MS1.Size);
      
end;
    Finally
      MS2.Free;
    End;
  
finally
    MS1.Free
  
end;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  
if  AreSameFiles(Edit1.Text , Edit2.text) then
  
begin
    ShowMessage(
'一样');
  
end else begin
    SHowMessage(
'不一样');
  
end;
end;
原文地址:https://www.cnblogs.com/ProgramBull/p/1787619.html