I don't usually have as much trouble with strings. I usually just treat them like arrays of Chars or as a fixed datachunk. They are just arrays of chars after all, right?
And when I use an array or a list in my structures, I'll have a Count variable --usually a 4-byte Integer for speed sake-- that reads just before the data.
So basically, I'll do something like this....
[pascal]var
MsgTxtLength: Integer;
MsgTxt: Array[0 .. 255] of Char;
...
BlockRead(FileStream, MsgTxtLength, SizeOf(MsgTxtLength));
for i := 0 to MsgTxtLength - 1 do
BlockRead(FileStream, MsgTxt[i], SizeOf(Char));
// or BlockRead(FileStream, MsgTxt[i], SizeOf(MsgTxt[i])); should work too!
...[/pascal]
It may seem like a slower way to do things, but to be honest, it's an array you're trying to retrive from file afterall right?
Bookmarks