Delphi Seattle / Firemonkey TFileStreams converting legacy byte files from Delphi 1 [on hold]

  

I’m converting a byte file from Delphi 1, to Delphi Firemonkey.

I’m very confused with the behaviour of TFileStream.

I have a record structure, with fixed width strings in it, and various other data-structures, array (from Delphi 1).

When I read in the file into a TFileStream using Read, and a size of the record structure, the record structure does not return the right result.

However, when I read in the individual fields one-by-one, using the same method it works.

I cannot figure this out.

Example.

This doesn’t work in Firemonkey (It does work in Delphi 1).

fs.read(Project , Sizeof(Project );

This code does work in firemonkey.

fs.Read(project.name, Sizeof(Name));
fs.Read(Project.date, Sizeof(date)); etc,etc,etc

What’s the difference? The original file is ANSI encoding. The only difference between the record structures is that Integers are now smallints.

Pretty baffled at the moment.

Answer — is to ensure in my case that every single array, and record structure was ‘packed’. I don’t fully understand the alignment of record structures/array in Delphi Seattle (or Delphi 1, for that matter), it has something to do with record alignment, but my code is now back to read(record, sizeof(record). Good!

Comments are closed.