If this is your first visit, be sure to check out the FAQ by clicking the link above. You have to register before you can post.

If you have recently signed up, please make sure you log in so that your activity is registered. This is required for automatic promotions to work and to ensure your account is not deleted during the registration process.

save/load a dynamic array

Hi, the save-procedure saves obviously 4 records, but the load-proc loads just one from the file test.DAT.
First thought might be that the load-proc doesn't work correctly, but the file test.MAP is read properly.
Second thought might be the save-proc isn't well programmed. I can't figure it out. I apriciate any valid hint.
Note: --- Manage Attachments --- isn't working so here is the code, if you need all files feel free to write to guido-lang@gmx.de
Thanks in advance

first of all use code tags when you're inserting large parts of the code. the way it is here will strip people of any desire to help you.
there is a lot of commented code which is unnecesary here and I assume it confuses you as well.
for example:
you read the number of records here:
FS.ReadBuffer(FileSize, SizeOf(FileSize));

but you never write it.

so my advice is clean you code, work through it step by step and you will surely fix all your problems.

1) Writing the array elements count onto the stream.
2) Looping through the array and writing out each element's contents, fully dereferenced, to the stream. That means the element and any part of its content has to contain no non-dereferenced pointers. Stream I/O functions expect the variables they are passed to not be or contain pointers; otherwise, you'll just store the pointer values, rather than the data in what the pointers point to.

More or less, you're handing an untyped bucket of data to the stream write function, and it doesn't know or care what the data actually is inside the bucket. Likewise, when you read data from a stream, you pass an empty bucket and how much untyped data you want to fill it with.

Also, the reads have to exactly mirror/balance the writes, or Things Go Bad (tm).

With the simple record structure you are using (all well-defined static scalar types), you can just write/read it straight up. However, if you put a string or other dynamic type into that record later, you'll have to add code in the element write function to "descend into" those dynamic types and read/write them appropriately dereferenced.