首页 > Windows开发 > 详细

Delphi_按字节比较两个文件

时间:2016-06-08 10:25:36      阅读:249      评论:0      收藏:0      [点我收藏+]

1、界面

技术分享

 

2、代码

procedure TForm1.btnSelectFile01Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    edtSelectFile01.Text := OpenDialog1.FileName;
  end;
end;

procedure TForm1.btnSelectFile02Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    edtSelectFile02.Text := OpenDialog1.FileName;
  end;
end;

procedure TForm1.btnCompareFileClick(Sender: TObject);
var ms1,ms2 :TMemoryStream;
    i :Integer;
    byte1, byte2 :Byte;
    iLenMin :Integer;
begin
  ms1 := TMemoryStream.Create;
  ms2 := TMemoryStream.Create;
  try
    ms1.LoadFromFile(Trim(edtSelectFile01.Text));
    ms2.LoadFromFile(Trim(edtSelectFile02.Text));

    if (ms1.Size <> ms2.Size) then
    begin
      Memo1.Lines.Add(ms1.Size <> ms2.Size : +inttostr(ms1.Size)+ , +inttostr(ms2.Size));
      Memo1.Lines.Add(‘‘);
//      Exit;
    end;

    iLenMin := ms1.Size;
    if (iLenMin > ms2.Size) then // 取小值
      iLenMin := ms2.Size;
    Memo1.Lines.Add(iLenMin : +inttostr(iLenMin));
    Memo1.Lines.Add(‘‘);

    ms1.Position := 0;
    ms2.Position := 0;
    for i:=0 to iLenMin-1 do
    begin
      byte1 := 0;
      byte2 := 0;
      ms1.Read(byte1, 1);
      ms2.Read(byte2, 1);
      if byte1<>byte2 then
      begin
        Memo1.Lines.Add(!= --> Idx : (+inttostr(i)+) --> +inttostr(byte1)+ , +inttostr(byte2));
      end;
    end;
  finally
    ms1.Free;
    ms2.Free;
  end;
end;

 

3、

4、

5、

 

Delphi_按字节比较两个文件

原文:http://www.cnblogs.com/CodeSkill/p/5569130.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!