Welcome to the new DelphiDabbler Code Library Documentation.

This is a new site that's currently running on alpha code. There are going to be bugs. If you discover any, please report them on the site's issues page (GitHub account required). Thanks.

Warning: Many URLs are going to change. Refer to the README file to discover which library project's documentation has been completed.

CalculateFile method

Project: MD5 Message Digest Unit

Unit: PJMD5

Class: TPJMD5

Applies to: ~>1.0

class function CalculateFile(const FileName: TFileName): TPJMD5Digest;

Description

This class method is very like the Calculate methods in that it provides a useful shortcut when you want to get the MD5 hash of a single file. Just call this method and pass the path to the required file in the FileName parameter and read the function result to get the required digest.

Like Calculate, there is no need to create an instance of TPJMD5 to use this method.

The disadvantage of this method over the similar ProcessFile method is that there is no way to change the default size of the buffer used to read the file. The buffer size is that given by the TPJMD5.DefReadBufferSize constant.

Example

Here’s how to check if the MD5 hashes of two files are the same:

function SameMD5(const FileName1, FileName2: TFileName): Boolean;
var
  D1, D2: TPJMD5Digest;
begin
  D1 := TPJMD5.CalculateFile(FileName1);
  D2 := TPJMD5.CalculateFile(FileName2);
  Result := D1 = D2;
end;