| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| All, We have the following structure in Delphi 5: TMyRecord = record Int1: integer; Int2: integer; Int3: integer; Date1: TDateTime; end; The size of this structure is 24 bytes (presumably since the record is unpacked). We are in the process of porting our code to Delphi 2007 and the record size for this is 20 bytes (presumably because D2007 packs by default even without the "packed record" syntax). Unfortunately this legacy code that we are porting requires us to continue to use a few of these unpacked records because there are contained in legacy binary files at client sites that need to still be read by the system. My question is, how can I emulate these records in D2007? I'm hoping that there is an "unpacked record" or some such that we can go to each record and fix them manually, or some compiler directive to do the same. Thanks! -ed |
|
#2
| |||
| |||
| "Ed Salgado" <ed@onedomain.com> wrote > ... requires us to continue to use a few of these unpacked > records > because there are contained in legacy binary files at client sites > that need to still be read by the system. My question is, how can > I emulate these records in D2007? Just edit your old records definitions to be packed and add padding as required. Then they will work in both old and new systems with your legacy data. One other thing, be sure to admonish the programmer(?) of the old system to not make that kind of mistake again. HTH, JohnH |
|
#3
| |||
| |||
| > TMyRecord = record > Int1: integer; > Int2: integer; > Int3: integer; > Date1: TDateTime; > end; > > The size of this structure is 24 bytes (presumably since the record is > unpacked). We are in the process of porting our code to Delphi 2007 and the > record size for this is 20 bytes (presumably because D2007 packs by default > even without the "packed record" syntax). Unfortunately this legacy code > that we are porting requires us to continue to use a few of these unpacked > records because there are contained in legacy binary files at client sites > that need to still be read by the system. If size does matter, never use an unpacked record, always a packed one. So simply add the packed keyword and add dummy fields to make it compatible with your existing binary files. You should also avoid generic types like integer but use fundamental types like longint instead... TMyRecord = packed record Int1: Longint; Int2: Longint; Int3: Longint; Dummy1: array[0..3] of Byte; Date1: TDateTime; end; -- Jens Gruschel http://www.pegtop.net |
|
#4
| |||
| |||
| Thanks for the input. Can we assume that all records need to be padded at the end or is there some field alignment being performed as well? "John Herbster" <herb-sci1_AT_sbcglobal.net> wrote in message news:489b2178@newsgroups.borland.com... > > "Ed Salgado" <ed@onedomain.com> wrote >> ... requires us to continue to use a few of these unpacked records >> because there are contained in legacy binary files at client sites that >> need to still be read by the system. My question is, how can >> I emulate these records in D2007? > > Just edit your old records definitions to be packed and add padding > as required. Then they will work in both old and new systems with > your legacy data. > > One other thing, be sure to admonish the programmer(?) of the > old system to not make that kind of mistake again. > > HTH, JohnH |
|
#5
| |||
| |||
| > Thanks for the input. Can we assume that all records need to be padded at > the end or is there some field alignment being performed as well? There is some field alignment. Following record has a size of 20 bytes (well, the Delphi versions I tested): TMyRecord = record A: Byte; B: Longint; C: Byte; D: Longint; E: Byte; end; After each byte field 3 padding bytes are inserted. If you are not sure you can do following test: var R: TMyRecorde; begin OffsetOfC := Integer(@R.C) - Integer(@R); -- Jens Gruschel http://www.pegtop.net |
|
#6
| |||
| |||
| Wow. This is going to be a problem. There are literally hundreds of records which we will have to field align. Any other way to handle this? Any other setting we can use to unpack all these records? Thanks again. "Jens Gruschel" <nospam@thisurldoesnotexist.com> wrote in message news:489b2788@newsgroups.borland.com... >> Thanks for the input. Can we assume that all records need to be padded >> at the end or is there some field alignment being performed as well? > > There is some field alignment. Following record has a size of 20 bytes > (well, the Delphi versions I tested): > > TMyRecord = record > A: Byte; > B: Longint; > C: Byte; > D: Longint; > E: Byte; > end; > > After each byte field 3 padding bytes are inserted. If you are not sure > you can do following test: > > var > R: TMyRecorde; > begin > OffsetOfC := Integer(@R.C) - Integer(@R); > > > -- > Jens Gruschel > http://www.pegtop.net |
|
#7
| |||
| |||
| Another question... TMyRecord = record Int1: integer; {4 bytes} Int2: integer; {4 bytes} Int3: integer; {4 bytes} Date1: TDateTime; {8 bytes} end; This logically looks like a 20 byte record and looks to be as packed as it can get so using the "packed record" shouldn't make a difference (or does it?). Why would this record be 24 bytes in D2007? -ed "Ed Salgado" <ed@onedomain.com> wrote in message news:489b1f79$1@newsgroups.borland.com... > All, > > We have the following structure in Delphi 5: > > TMyRecord = record > Int1: integer; > Int2: integer; > Int3: integer; > Date1: TDateTime; > end; > > The size of this structure is 24 bytes (presumably since the record is > unpacked). We are in the process of porting our code to Delphi 2007 and > the record size for this is 20 bytes (presumably because D2007 packs by > default even without the "packed record" syntax). Unfortunately this > legacy code that we are porting requires us to continue to use a few of > these unpacked records because there are contained in legacy binary files > at client sites that need to still be read by the system. My question is, > how can I emulate these records in D2007? I'm hoping that there is an > "unpacked record" or some such that we can go to each record and fix them > manually, or some compiler directive to do the same. > > Thanks! > > -ed > > |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.