[fpc-pascal] How to find address of record member
Bo Berglund
bo.berglund at gmail.com
Sun Jul 8 18:28:34 CEST 2018
On Sun, 8 Jul 2018 17:16:01 +0200, Martin
<fpc at mfriebe.de> wrote:
>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
I tried this:
var
offs: word;
begin
...
offs := @FAppData.Info - @FAppData; //Info is 4th member of record
address := AppBase + (AppNumber -1) * (SizeOf(TAppData) div 2) +
offs;
But it was not accepted by the compiler (on the offs := line)...
Error: Operator not applicable to this operand type
FAppData is declared in the class definition like this:
TDongle = class
private
{ Private declarations }
FAppNumber,
FKeySerial,
FKeyFound: boolean;
FAppData: TAppData;
....
I don't know the command 'absolute' and how it can be applied here in
a class definition.
--
Bo Berglund
Developer in Sweden
More information about the fpc-pascal
mailing list