Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 1.23 KB

TPJMD5-Finalize.md

File metadata and controls

43 lines (31 loc) · 1.23 KB

Finalize method

Project: MD5 Message Digest Unit

Unit: PJMD5

Class: TPJMD5

Applies to: ~>1.0

procedure Finalize;

Description

Finalizes the current MD5 hash and sets the Finalized property to True.

Any attempt to add more data to the hash after calling this method raises an EPJMD5 exception.

Finalize is called internally when the Digest property is read. This means that there is rarely any need to call Finalize explicitly.

Calling this method more than once has no effect - the digest is finalized only once. This ensures that calling Finalize before reading Digest, or reading Digest more than once, is safe.

Example

var
  MD5: TPJMD5;
begin
  MD5 := TPJMD5.Create;
  try
    MD5.Process('Foo', TEncoding.ASCII);
    ShowMessage(BoolToStr(MD5.Finalized, True)); // will display "False"
    MD5.Finalize;
    // Further calls to MD5.Process will raise exception now
    ShowMessage(BoolToStr(MD5.Finalized, True)); // will display "True"
    ShowMessage(MD5.Digest);  // Digest implicitly cast to string
  finally
    MD5.Free;
  end;
end;