Results 1 to 4 of 4

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.

  3. #3
    one thing you need to know about streams is that they work as huge stacks of data chunks. how you access them, depends on what you drop into. as SilverWarior said, with a fixed size chunk you just need to get or to put chunks one after the other. with variable size you need some kind of info in advance to be able to get/put data chunks as you need them. you can put a longint just before the data chunk, so you know the size before read it. also you can keep an index to where you put things inside the stream.

  4. #4
    Hi, still no answer ? Have you fixed this or not yet ?

    VPN Sai Mannat AnyDesk
    Last edited by davido; 29-02-2020 at 08:34 PM.

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
  •