DELPHI:
uses IdHash,IdHashMessageDigest;
function GetFileMd5Code(AFileName: string): string;
var
LMd5: TIdHashMessageDigest5;
S, S1: string;
i: Integer;
LFileStream: TMemoryStream;
Digest: T4x4LongWordRecord;
begin
SetLength(S, 16);
LFileStream := TMemoryStream.Create;
LFileStream.LoadFromFile(AFileName);
LMd5 := TIdHashMessageDigest5.Create;
Digest := LMd5.HashValue(LFileStream);
Move(Digest, S[1], 20);
for i := 1 to Length(S) do begin
S1 := S1 + Format('%02x', [Byte(S[i])]);
end;
while Pos(' ', S1) > 0 do S1[Pos(' ', S1)] := '0';
Result := S1;
end;
BORLAND C++:
AnsiString TForm1::GetFileMd5Code(AnsiString AFileName)
{
TIdHashMessageDigest5 *LMd5= new TIdHashMessageDigest5();
AnsiString S[16], S1;
int i;
TMemoryStream *LFileStream = new TMemoryStream();
LFileStream->LoadFromFile(AFileName);
Sysutils::TBytes LBytes;
LBytes = LMd5->HashStream(LFileStream);
delete LMd5;
delete LFileStream;
return StringOf(LBytes);
}