Results 1 to 2 of 2

Thread: Need some help / advice with reading from streams

  1. #1

    Need some help / advice with reading from streams

    Hi all.
    Dunno if anybody even answers here but i try.

    In short:
    If i write structs (UndoBlock) to streams like that:
    Code:
    hugestream.Write(UndoBlock, sizeof(UndoBlock));
    This "kinda" works. Data is written and it seems that its written correctly.

    But i have a real problem reading it back.
    Do i need to read into array?
    The amount of writings depends on how many changes user made to the map.
    I can count that..

    But when im trying to read the numwritten i get garbage.
    Writing to stream (im just saving old block before modifying):
    Code:
    hugestream.Write(sbs, sizeof(sbs));
    Reading back:
    Code:
      for i:=0 to NumWritten-1 do
      begin
        s.read(sbs, sizeof(sbs)); // is this even correct way to read???
    
    
       ShowMessage('setstate '+IntToStr(sbs.LidTile));  // garbage displayed
       end;
    The cbs record only has Byte and Word fields. Nothing else.
    maybe the record size is bad? Maybe i should add "pad"?

    Or i just should read back every record item (field) one by one and not whole struct at once?

    I have used lots of streams and stuff in my other projects but i always get the issues reading back stuff.
    Im forgetting stuff.
    Last edited by hwnd; 07-07-2019 at 03:52 PM.

  2. #2
    If your record has fixed size and don't contain any referenced types or pointers then you should be able to read such record back from stream directly into a record structure without any problem.

    Would you mind showing the structure of your records so we can verify that they don't contain any data structure that might cause problems. Besides it will give us opportunity to create a test case using your record structure to help locate your problem.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Comodo SSL