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中的字符串分割

Delphi删除只读文件

Delphi edit右键系统菜单加自定义菜单项

Delphi 本地数据库备份与还原(Delphi)

Delphi检测程序内存泄漏

Delphi 如何通过进程句柄判断该进程是否已退出?

Delphi 屏幕渐变效果的源代码

Delphi转换 tcolor 到 html 颜色串

Delphi的stringreplace 字符串替换函数

Delphi winapi: settimer、killtimer - 创建与移除高性能定时器

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



打赏

取消

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

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

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

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

评论

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