Recent

Author Topic: [SOLVED] Undo/redo in TSTringGrid with TStream  (Read 295 times)

carlangas

  • Jr. Member
  • **
  • Posts: 59
[SOLVED] Undo/redo in TSTringGrid with TStream
« on: October 06, 2024, 08:34:11 pm »
I am sure this must be obvious, but I couldn't manage to find out an easy way to implement undo/redo in a StringGrid using TStream, which I see in this forum as a convenient solution.

This is what I do:

Code: Pascal  [Select][+][-]
  1. var
  2.  Copia: TMemoryStream;
  3.  
  4. ...
  5.  
  6. Copia:=TMemoryStream.Create;
  7.  
  8. ...
  9.  
  10.  
  11. LaTabla.SaveToStream(Copia);
  12.  
  13. ...
  14.  
  15. LaTabla.LoadFromStream(Copia);
  16.  
  17.  

When loading from the stream, I get an
Code: Pascal  [Select][+][-]
  1. In 'stream:' (line 1 pos 1): Root element is missing.
error.

What I want to do is to back up the content of the grid and be able to restore it.

What is the mistake I make?
« Last Edit: October 07, 2024, 10:04:08 am by carlangas »

bobby100

  • Sr. Member
  • ****
  • Posts: 260
    • Malzilla
Re: Undo/redo in TSTringGrid with TStream
« Reply #1 on: October 06, 2024, 10:27:16 pm »
Dunno if SaveOptions are affecting the SaveToStream, but this looks like SaveOptions problem.

jamie

  • Hero Member
  • *****
  • Posts: 6733
Re: Undo/redo in TSTringGrid with TStream
« Reply #2 on: October 06, 2024, 10:48:05 pm »
Did you reset the Position back to 0 before trying to reload it?
The only true wisdom is knowing you know nothing

carlangas

  • Jr. Member
  • **
  • Posts: 59
Re: Undo/redo in TSTringGrid with TStream
« Reply #3 on: October 07, 2024, 10:03:26 am »
Exactly. It was that. I did not manage to find a usage example for doing so.

It was just a matter of doing
Code: Pascal  [Select][+][-]
  1. Copia.Position:=0;
before loading it back.

So, for anyone having the same issue and not finding the needed doc, this is how I end up doing it:
Code: Pascal  [Select][+][-]
  1. var
  2.  Copia: TMemoryStream;
  3.  
  4. ...
  5.  
  6. Copia:=TMemoryStream.Create;
  7.  
  8. ...
  9.  
  10.  
  11. LaTabla.SaveToStream(Copia);
  12.  
  13. ...
  14.  
  15. Copia.Position:=0;
  16. LaTabla.LoadFromStream(Copia);
  17.  

Thanks, Jamie.

 

TinyPortal © 2005-2018