ReadFromStream method

Project: Binary Version Information Manipulation Units.

Unit: DelphiDabbler.Lib.VIBin.Resource.

Class: TVIBinResource

Applies to: ~>1.0

procedure ReadFromStream(const Stream: IStream);

Description

Reads the binary representation of the version information from a stream then parses the data and stores it in this object.

Parameter:

Exception:

Example

The following example shows how to read data from a file into a Unicode version information object.

The code opens the file using a TFileStream object. Since ReadFromStream expects an IStream instance rather than a TStream, a TStreamAdapter object is used to wrap the TStream to provide the required IStream interface.

begin
  var VI := TVIBinResource.Create(vrtUnicode);
  try
    var FS := TFileStream.Create('C:\MyVersionData', fmOpenRead);
    var FSA: IStream := TStreamAdapter.Create(FS, soOwned);
    VI.ReadFromStream(FSA);
    // ...
    // Do something with VI here
    // ...
  finally
    VI.Free;
  end;
end;

Note that we pass ownership of file stream FS to the TStreamAdapter instance FSA, which means that FS will be freed when FSA is destroyed. FSA will be destroyed automatically when it goes out of scope.

For brevity, the TFileStream instance and its IStream wrapper could be created on the fly as follows:

    VI.ReadFromStream(
      TStreamAdapter.Create(
        TFileStream.Create('C:\MyVersionData', fmOpenRead),
        soOwned  
      )
    );

See Also