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
(http://delphi.miningco.com) site, each week!

04/20/99 Delphi and ActiveX
http://delphi.miningco.com/library/weekly/aa042099.htm
Let's create ActiveX form that can be displayed and run from within Web
browsers.

04/13/99 - Statements/Properties/Variables
http://delphi.miningco.com/library/weekly/aa041399.htm
Delphi for Beginners: The basic layout of a Pascal/Delphi program.

04/06/99 - GExperts
http://delphi.miningco.com/library/weekly/aa040699.htm
Review of this very useful collection of Delphi Experts.

03/30/99 - Experts and Wizards
http://delphi.miningco.com/library/weekly/aa033099.htm
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
http://delphi.miningco.com/library/weekly/mpreviss.htm

2. Check http://delphi.miningco.com/mlibrary.htm for Delphi related
components, articles and links in general.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Zarko Gajic, Delphi Programming guide, TMC
http://delphi.miningco.com
delphi.gu...@miningco.com
Free newsletter:
http://delphi.miningco.com/gi/pages/mmail.htm
"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
file.

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 :-

begin
  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
        WriteListBegin;
        for j := 0 to RowCount - 1 do
          WriteString(Cells[i, j]);
        WriteListEnd;
      end; {for i := 0 to ColCount -1}
    end; {with StringGrid1}
    FlushBuffer;
    AStream.SaveToFile(FileName);
    Free;
  end; {with AWriter}
  AStream.Free;
end;

Alan Lloyd
alangll...@aol.com

Re:News from Delphi Programming Home Page - April 1999


Im Artikel <19990420144206.07872.00000...@ngol01.aol.com>, alangll...@aol.com
(AlanGLLoyd) schreibt:

Quote
>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 :-(

DoDi

Other Threads