Project: Binary Version Information Manipulation Units.
Unit: DelphiDabbler.Lib.VIBin.Resource.
Class: TVIBinResource
Applies to: ~>1.0
procedure WriteToStream(const Stream: IStream);
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.
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:
- Open a TFileStream instance onto a newly created file.
- Because WriteToStream expects an IStream parameter, create a TStreamAdapter instance to provide an IStream interface to TFileStream.
- 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
)
);