[fpc-pascal] How to find address of record member
Martin
fpc at mfriebe.de
Sun Jul 8 17:16:01 CEST 2018
On 08/07/2018 17:07, Bo Berglund wrote:
> Say I have a record type defined like this:
>
> TAppData = packed record //Total 8 bytes per app
> ActiveToken: word; //Matches constant for app if active
> Option: word; //16 option bits
> ExpDate: word; //Integer TDateTime values
> Info: word; //16 info bits
> end;
>
> The data is stored in a security dongle memory which can be accessed
> only a word at a time by its word address 0..55.
>
> I want to write my code such that the address to the individual member
> is calculated automatically so if the record type is modified it will
> still work.
>
var AppData: TAppData absolute 0;
begin
writeln( ptrint( @AppData.Option ));
You can also take a variable without "absolute"
@AppData.Option - @AppData
More information about the fpc-pascal
mailing list