Recent

Author Topic: Populating and manipulating a TStringGrid instance  (Read 326 times)

msocorcim

  • New member
  • *
  • Posts: 8
Populating and manipulating a TStringGrid instance
« 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
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

wp

  • Hero Member
  • *****
  • Posts: 9902
Re: Populating and manipulating a TStringGrid instance
« Reply #1 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.
« Last Edit: June 28, 2022, 11:33:25 pm by wp »

Handoko

  • Hero Member
  • *****
  • Posts: 4679
  • My goal: build my own game engine using Lazarus
Re: Populating and manipulating a TStringGrid instance
« Reply #2 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