Lazarus

Programming => LCL => Topic started by: msocorcim on June 24, 2022, 11:55:45 pm

Title: Populating and manipulating a TStringGrid instance
Post by: msocorcim on June 24, 2022, 11:55:45 pm
Hello All,

I had some difficulties loading data into TStringGrid and found this example by the forum user Handoko very helpful.
https://forum.lazarus.freepascal.org/index.php/topic,37181.msg249361.html#msg249361 (https://forum.lazarus.freepascal.org/index.php/topic,37181.msg249361.html#msg249361)
The example prog is extended to Load and Save via a TMemoryStream object and to observe StringGrid behavior under various conditions.

The biggest takeaway for me was that TStream descendants need their internal pointer reset to 0 before reading them with LoadFromStream methods (I'd assumed this was done automatically, but then why would it be?), otherwise a Document Root isn't found by the xmlparser when the Stream is read.

Hope someone finds this useful!

Dennis Reichel aka Msocorcim
Title: Re: Populating and manipulating a TStringGrid instance
Post by: wp on June 25, 2022, 12:17:09 am
The biggest takeaway for me was that TStream descendants need their internal pointer reset to 0 before reading them with LoadFromStream methods (I'd assumed this was done automatically, but then why would it be?), otherwise a Document Root isn't found by the xmlparser when the Stream is read.
Imagine a stream like an old-fashined tape-recorder. When you write to the stream, the "tape" advances. After writing, the stream is at the end of the data. Before you can read you must "rewind" the tape to the beginning. This is done by calling Stream.Position := 0.
Title: Re: Populating and manipulating a TStringGrid instance
Post by: Handoko on June 28, 2022, 09:15:29 pm
Hope someone finds this useful!

Surely some will find it useful.
Thank you for showing the example on how to use stream.
TinyPortal © 2005-2018