peterbone
21-06-2004, 01:18 PM
I have a question regarding 2 different methods of writing a structure to a stream. firstly, writing it as one variable and secondly writing the variables in the stream individually. I would expect both methods to produce the same data in the stream and in the same order - but that isn't the case.
TStructure = record
variable1 : byte;
variable2 : Single;
end;
var
AStream : TMemoryStream;
AStruct : TStructure;
AStream := TMemoryStream.Create;
AStream.Seek(0, 0);
// method 1
AStream.Write(AStruct, SizeOf(TStructure));
// method 2
AStream.Write(AStruct.variable1, 1);
AStream.Write(AStruct.variable2, SizeOf(Single));
So, any idea why they don't give the same results? Does the first method write the variables in the order they are declared in the structure or in some other order? I should say that I've simplified my problem for this example - I have 7 variables or different types in my structure.
Peter
TStructure = record
variable1 : byte;
variable2 : Single;
end;
var
AStream : TMemoryStream;
AStruct : TStructure;
AStream := TMemoryStream.Create;
AStream.Seek(0, 0);
// method 1
AStream.Write(AStruct, SizeOf(TStructure));
// method 2
AStream.Write(AStruct.variable1, 1);
AStream.Write(AStruct.variable2, SizeOf(Single));
So, any idea why they don't give the same results? Does the first method write the variables in the order they are declared in the structure or in some other order? I should say that I've simplified my problem for this example - I have 7 variables or different types in my structure.
Peter