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.

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