[lazarus] Streaming examples

Sebastian Günther sguenther at gmx.de
Thu Jun 29 16:53:41 EDT 2000


Hi *,

as I know that some of you would ask for this anyway, here are some
examples for using the new FCL streaming code:

  type
    Obj: TMyClass;

Writing a binary DFM:

  WriteComponentResFile('test.res', Obj);

Writing a XML serialisation file:

  var
    Writer: TWriter;
    Driver: TAbstractObjectWriter;
    XMLDoc: TXMLDocument;
  begin
    XMLDoc := TXMLDocument.Create;
    Driver := TXMLObjectWriter.Create(XMLDoc);
    Writer := TWriter.Create(Driver);
    Writer.WriteRootComponent(Obj);
    Writer.Free;
    Driver.Free;
    WriteLn;
    WriteXMLFile(XMLDoc, Output);
    XMLDoc.Free;
  end;

Reading a binary DFM:

  var
    Stream: TStream;
  begin
    Stream := TFileStream.Create('test.res', fmOpenRead);
    Stream.ReadComponentRes(Obj);
    Stream.Free;
  end;


For the XML writer, an option for appending a 'persistence node'
(element node which is the root node for a streamed component') will be
added soon.
As I wrote in my first mail, the readers will be extended to support
other file formats such as XML; additionally the component archive will
act as a replacement for the resource handling stuff in VCL: The archive
(which exists only in memory, it does not use external files for storing
anything) just knows how it can load streamed components. (i.e. which
'driver' must be used, and in which archive file it has to search for a
component with a given name.)

I think the examples given above will be sufficient to implement
streaming in Lazarus, as it's really simple to understand. Perhaps even
for Shane ;)


- Sebastian






More information about the Lazarus mailing list