Board index » delphi » News from Delphi Programming Home Page - April 1999

News from Delphi Programming Home Page - April 1999

Hi everybody...

New articles on the Delphi Programming
( site, each week!

04/20/99 Delphi and ActiveX
Let's create ActiveX form that can be displayed and run from within Web

04/13/99 - Statements/Properties/Variables
Delphi for Beginners: The basic layout of a Pascal/Delphi program.

04/06/99 - GExperts
Review of this very useful collection of Delphi Experts.

03/30/99 - Experts and Wizards
How "magic" can extend and enhance the way we work with the Delphi IDE.

More from Delphi Programming Home Page

1. Even more tutorials and articles on the Delphi Programming Home Page

2. Check for Delphi related
components, articles and links in general.

Zarko Gajic, Delphi Programming guide, TMC
Free newsletter:
"We mine the net so you don't have to"


Re:News from Delphi Programming Home Page - April 1999

I have been trying to store TStringGrid properties and have been using TWriter
with a TMemoryStream and TMemoryStream.SaveToFile / LoadFromFile.

Using  Stream.WriteDescendent(StringGrid, nil),
Stream.WriteComponent(StringGrid), Writer.WriteComponent or
Writer.WriteRootComponent puts only a limited set of properties into the stream
and file. Only Stream.WriteDescendent(StringGrid, Form) puts all the properties
into the stream / file. I have to kludge by using Stream.WriteDescendent and
then TWriter to write WriteBeginList, WriteStrings, and Wri{*word*249}dList for the
cell contents. I have checked the store of the properties by inspecting the

Anyone comment on this or why I cannot use TWriter to write all the SG
properties. Or some code examples please.

This is the code that works :-

  AStream := TMemoryStream.Create;
  AStream.WriteComponent(StringGrid1, Form1);
  AWriter := TWriter.Create(AStream, 1024);
  with AWriter do begin
    with StringGrid1 do begin
      for i := 0 to ColCount - 1 do begin
        for j := 0 to RowCount - 1 do
          WriteString(Cells[i, j]);
      end; {for i := 0 to ColCount -1}
    end; {with StringGrid1}
  end; {with AWriter}

Alan Lloyd

Re:News from Delphi Programming Home Page - April 1999

Im Artikel <>,
(AlanGLLoyd) schreibt:

>Anyone comment on this or why I cannot use TWriter to write all the SG
>properties. Or some code examples please.

TWriter is the low level object, that only does what it's told to do. A
WriteDescendent will tell it to save the published properties only. All other
properties, i.e. all arrays, should be saved by DefineProperties, where you
refer to your code to read and write the additional properties. There you can
refer to your existing code, with the stream creation etc. removed, since the
routine receives the already existing TWriter as an argument. In your example,
this will be the With AWriter Do... block.

BTW, I had problems to save the Objects of a TStringList, since TWriter doesn't
support Nil objects. Of course I had to implement the output of the object data
myself, but couldn't find a solution for simply writing a mark, that no data
exists for a Nil object. You may run into similar problems, when you want to
read back the properties later. Then no indication exists, how many elements
should be read in a Begin/EndList block, and into which array elements the data
should be stored. As a workaround I stored the index of the element prior to
the data, and tested for the existence of such an index value or for an EndList
in the according read loop.

Because of all these problems I'm experimenting with my own I/O now, based on
overloaded prop(var x: y) methods in a new TStreamer object. Then it should be
possible to write a *single* method, that is given a TStreamer object, and
calls it's prop methods for all properties. Depending on the nature of the
TStreamer, a TInStreamer will then copy the data into to fields, or a
TOutStreamer will save the data into the stream.

This method works for all data structures (e.g. records), independently from
any RTTI. It also allows to write *and* later read the data with a single
subroutine, whereas TReader and TWriter require different  subroutines, with
duplicate coding efforts and probability of errors. IMO that's important, since
no RTTI will help you in implementing the I/O in DefineProperties :-(


Other Threads