delphi 读取文件的MD5值


本文整理自网络,侵删。

  
unit Unit1;

interface

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

type
TForm1 = class(TForm)
btn1: TButton;
OpenSwf1: TOpenDialog;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
private
function StreamToMD5(S: TFileStream): String;
{ Private declarations }
public
{ Public declarations www.delphitop.com}
end;

type
TMD5 = class(TIdHashMessageDigest5);

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.btn1Click(Sender: TObject);
var
filesen:TFileStream;
begin
if OpenSwf1.Execute then
begin
filesen:=TFileStream.Create(OpenSwf1.FileName,fmOpenRead or fmShareExclusive);
edt1.Text:=StreamToMD5(filesen);
filesen.Free;
end;
end;

//读文件MD5值
function TForm1.StreamToMD5(S: TFileStream): String;
var
Md5Encode: TMD5;
begin
Md5Encode:= TMD5.Create;
try
Result :=Md5Encode.HashStreamAsHex(s) ;
finally
Md5Encode.Free;
end;
end;

end.

相关阅读 >>

Delphi xe2 idhttp 获取utf-8编码中文网页

Delphi提示‘error loading midas.dll’的原因及解决方案

Delphi tfdmemtable 更新到数据库

Delphi 内存管理[4]

Delphi fastreport 直接列印

Delphi 通过pid获取进程名

Delphi百度网盘真实地址解析

Delphi简单读取网上的文本文件

Delphi程序版本信息设置说明

Delphi强制关闭执行程序(杀进程)

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



打赏

取消

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

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

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

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

评论

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