I have a very big eeprom structure which I will simplify for demonstration like this:
If later in code I try to pass TAiSettings var type to function like this:
then when I try to access record elements I expected them to be in eeprom, but it seams that they point to ram instead, since this reads totally wrong values:
I have found a workaround replacement call like this:
and it works fine if I change CalcAi() to be like this:
This is very ugly and reminds me like working with C. Not to mention that my eeprom structures have complex records in thousands of bytes and I would literally have to use this ugly workaround in hundreds of places, and introduce dozens of pointers for each subrecord that I need. Is there some other way? Maybe I can somehow redefine function parameter type so it is told to point to eeprom? Can compiler somehow know that any function record parameter points to eeprom? Can it be fixed anyhow?
Code
type
TEnum = (Zero, One);
TAiSettings = record
Correction : TEnum;
Filter : TEnum;
end;
TSettings = record
AI : array[1..6] of TAiSettings;
General : TEnum;
end;
var
{$EEPROM}
Settings: TSettings, locked;
ptr: pointer to TAiSettings;
TEnum = (Zero, One);
TAiSettings = record
Correction : TEnum;
Filter : TEnum;
end;
TSettings = record
AI : array[1..6] of TAiSettings;
General : TEnum;
end;
var
{$EEPROM}
Settings: TSettings, locked;
ptr: pointer to TAiSettings;
If later in code I try to pass TAiSettings var type to function like this:
Code
CalcAi(Settings.AI[3]);
then when I try to access record elements I expected them to be in eeprom, but it seams that they point to ram instead, since this reads totally wrong values:
Code
procedure CalcAi(var SettingsAi: TAiSettings);
begin
if (SettingsAi.Correction = One) then // <<< value of SettingsAi.Correction is wrong
Write(LCDout, 'One');
else
Write(LCDout, 'Zero');
endif;
end;
begin
if (SettingsAi.Correction = One) then // <<< value of SettingsAi.Correction is wrong
Write(LCDout, 'One');
else
Write(LCDout, 'Zero');
endif;
end;
I have found a workaround replacement call like this:
Code
ptr := @Settings.AI[i]; // eeprom pointer works well
CalcAi(ptr); // eeprom pointer works well
CalcAi(ptr); // eeprom pointer works well
and it works fine if I change CalcAi() to be like this:
Code
procedure CalcAi(var SettingsAiPtr: pointer to TAiSettings);
begin
if (EEpromPtr(SettingsAiPtr)^.Correction = One) then
Write(LCDout, 'One');
else
Write(LCDout, 'Zero');
endif;
end;
begin
if (EEpromPtr(SettingsAiPtr)^.Correction = One) then
Write(LCDout, 'One');
else
Write(LCDout, 'Zero');
endif;
end;
This is very ugly and reminds me like working with C. Not to mention that my eeprom structures have complex records in thousands of bytes and I would literally have to use this ugly workaround in hundreds of places, and introduce dozens of pointers for each subrecord that I need. Is there some other way? Maybe I can somehow redefine function parameter type so it is told to point to eeprom? Can compiler somehow know that any function record parameter points to eeprom? Can it be fixed anyhow?