Re: Calculate field offset in a typed record

From: AlanGLLoyd (alanglloyd_at_aol.com)
Date: 12/29/03


Date: 29 Dec 2003 08:52:05 GMT

In article <bsntsn$orc$1@ctb-nnrp2.saix.net>, "Rudi Loos" <loos@intekom.co.za>
writes:

>TMyrecord = packed record
> Field1 : Integer;
> Field2 : Array [0..25] of byte;
> ......
> Field24 : Word;
> Field25 : String[13]
> end;
>
>I would like to calculate the offset to field24 with respect to MyRecord.
>I have large records that I use to communicate with an electronic device and
>want to pass an address and byte count so that I will only need to read 2
>bytes at address Field24.
>I tried to subtract the pointers but I get an error "operation not
>applicable"
>

TMyPartrecord = packed record
    Field1 : Integer;
    Field2 : Array [0..25] of byte;
    ......
    Field22 : whatever;
 end;

    MyRecordField23Offset := SizeOf(TMyPartRecord);

... and similarly for any other offset.

AlanLloyd
alanglloyd@aol.com