Skip to content

Latest commit

 

History

History
69 lines (48 loc) · 2.13 KB

TVIBinResource-WriteToStream.md

File metadata and controls

69 lines (48 loc) · 2.13 KB

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:

  • Stream -- IStream interface to the stream that is to be written to.

Exception:

  • EVIBinVarRec raised if any error is encountered while writing to the stream.

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