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.

WriteToStream method

Project: Binary Version Information Manipulation Units.

Unit: DelphiDabbler.Lib.VIBin.Resource.

Class: TVIBinResource

Applies to: ~>1.0

procedure WriteToStream(const Stream: IStream);

Description

Writes the binary representation of the version information to a stream.

Parameter:

Exception:

Example

Say you have a Unicode TVIBinResource object containing version information data that you want to write to a file. This can be achieved as follows:

  1. Open a TFileStream instance onto a newly created file.
  2. Because WriteToStream expects an IStream parameter, create a TStreamAdapter instance to provide an IStream interface to TFileStream.
  3. Write the data to the stream using WriteToStream.

The following code does the job

begin
  var VI: TVIBinResource.Create(vrtUnicode);
  try
    // ...
    // Add some data to VI here
    // ...
    var FS := TFileStream.Create('C:\MyFile', fmCreate);
    var FSA: IStream := TStreamAdapter.Create(FS, soOwned);
    VI.WriteToStream(FSA);
  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.WriteToStream(
      TStreamAdapter.Create(
        TFileStream.Create('C:\MyFile', fmCreate), 
        soOwned
      )
    );

See Also