zoukankan      html  css  js  c++  java
  • Delphi_按字节比较两个文件

    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、

  • 相关阅读:
    PHP面试题4
    php面试题2
    php基础面试题1
    mysql添加索引命令
    lnmp初步学习知识整理
    代码运行的自由
    Lein droid
    关于Domain Sepcific Lang
    JavaScript倒计时类
    三国小记
  • 原文地址:https://www.cnblogs.com/CodeSkill/p/5569130.html
Copyright © 2011-2022 走看看