码迷,mamicode.com
首页 > Windows程序 > 详细

Delphi_按字节比较两个文件

时间:2016-06-08 10:28:36      阅读:366      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!