Forum > LCL

Populating and manipulating a TStringGrid instance

(1/1)

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

--- Quote from: msocorcim on June 24, 2022, 11:55:45 pm ---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.

--- End quote ---
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.

Handoko:

--- Quote from: msocorcim on June 24, 2022, 11:55:45 pm ---Hope someone finds this useful!

--- End quote ---

Surely some will find it useful.
Thank you for showing the example on how to use stream.

Navigation

[0] Message Index

Go to full version