delphi开发获取文件MD5值


本文整理自网络,侵删。

 
unit Umain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,IdHashMessageDigest,IdGlobal,IdHash;

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    Memo1: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    function StreamToMD5(s:TFileStream):string;
    { Private declarations }

  public
    { Public declarations }
  end;

  type
      TMD5=class(TIdHashMessageDigest5);

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
    filesen:TFileStream;
    str:string;
begin
    if opendialog1.Execute then
    begin
        filesen:=TFileStream.Create(opendialog1.FileName,fmopenread or fmshareExclusive);
        str:=StreamToMD5(filesen);
        memo1.Lines.Add(str);
        filesen.Free;
    end;
end;

function TForm1.StreamToMD5(s:TFileStream):string;
var
    MD5Encode:TMD5;
    long:T4x4LongWordRecord;
begin
    MD5Encode:=TMD5.Create;
    try
        long:=md5encode.HashValue(s);
        result:=MD5Encode.AsHex(long);
    finally
        MD5Encode.Free;
    end;
end;

end.
――――――――――――――――

原文链接:https://blog.csdn.net/xxkku521/article/details/8815142

相关阅读 >>

Delphi firedac 下的 sqlite [7] - 备份、优化、事务(transaction)

Delphi 设置系统启动文件夹自身开机自动运行

Delphi 文件分割合并

Delphi 调用浏览文件夹 selectdirectory

Delphi 封装frame到dll文件

tidtcpclient控件中文指南

Delphi 各种tstream(流)介绍

Delphi清空回收站

Delphi 调试ios时出现 please specify exact device preset uuid

Delphi中in的使用

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...