是否可以使用delphi获取TStream的MD5校验和?

时间:2018-10-31 18:51:44

标签: delphi md5 tstream

我修改了File MD5 checksum帖子中提供的答案,以便它可能以以下方式适用于TStream

function TForm1.check_sum_attachments(attachment_stream_:TStream):String;
var
  IdM5:TIdHashMessageDigest5;
  attachment_stream:TStream;
begin
  IdM5.Create;
  attachment_stream.CopyFrom(attachment_stream_, attachment_stream_.Size);
  try
    Result := IdM5.HashStreamAsHex(attachment_stream);
  finally
    attachment_stream.Free;
    IdM5.Free;
  end;
end;

然后我以以下方式连接到imap服务器以获取附件流时调用此函数

if IdMessage1.MessageParts.Items[current_email_part] is TIdAttachment then
        begin

          attachment_stream := TIdAttachment(IdMessage1.MessageParts.Items[current_email_part]).OpenLoadStream;
          try
           AttachmentsTable.Insert;
           blob_field := AttachmentsTable.FieldByName('attachment');
           blob_stream := AttachmentsTable.CreateBlobStream(blob_field, bmWrite);
              try
                blob_stream.CopyFrom(attachment_stream, attachment_stream.Size);
                attachment_checksum := check_sum_attachments(blob_stream);
              finally
                blob_stream.Free;
                AttachmentsTable.Post;
              end;
           finally
            TIdAttachment(IdMessage1.MessageParts.Items[current_email_part]).CloseLoadStream;
           end;

但是我收到错误消息“模块'Project3.exe'中地址0040823E的访问冲突,读取了地址C22677E9”

任何人在尝试获取我的Blob流的校验和方面的帮助,我将不胜感激。我可能会也可能不会走上正确的道路,因此将不胜感激其他解决方案。

我一般都不熟悉delphi和编程。

0 个答案:

没有答案