{$IFDEF FPC }
{$MODE OBJFPC }
{$MODESWITCH ADVANCEDRECORDS }
{$MODESWITCH AUTODEREF- }
{$MODESWITCH ALLOWINLINE }
{$ENDIF }
{$MODESWITCH ANSISTRINGS- }
{$LONGSTRINGS OFF }
{$WRITEABLECONST ON }
{$APPTYPE CONSOLE }
program PropsExcep;
uses windows;
type
PPropertiesRecord4 = ^PropertiesRecord4;
PropertiesRecord4 = record
private
TheField : integer;
procedure init;
procedure SetTheField(value : integer);
function GetTheField : integer;
public
property Field : integer read GetTheField write SetTheField;
end;
procedure PropertiesRecord4.init;
begin
TheField := 4;
end;
procedure PropertiesRecord4.SetTheField(value : integer);
begin
TheField := value;
end;
function PropertiesRecord4.GetTheField : integer;
begin
if IsBadReadPtr(@Self, sizeof(Self)) then exit($AAAA);
Result := TheField;
end;
var
Record4ptr : PPropertiesRecord4;
begin
// see how the getter handles the exception
Record4ptr := PPropertiesRecord4($44); // load a bad address
// this should cause an exception in kernel32 and as a result the value
// returned should be $AAAA
writeln('The field : ', Record4Ptr^.Field);
end.