I am searching for information and found samples in the rtl documentation, but i am not able to run the samples
Is the sample or my installation broken ?
(Yes i know this is not a new fpc installation, but according the major version of the documentation. But the same happens with other fpc's)
Code from here
https://www.freepascal.org/docs-html/3.2.0/rtl/typinfo/getobjectprop.htmlprogram example5;
{ This program demonstrates the GetObjectProp function }
{$mode objfpc}
uses rttiobj,typinfo;
Var
O : TMyTestObject;
PI : PPropInfo;
NO1,NO2 : TNamedObject;
begin
O:=TMyTestObject.Create;
NO1:=TNamedObject.Create;
NO1.ObjectName:='First named object';
NO2:=TNamedObject.Create;
NO2.ObjectName:='Second named object';
O.ObjField:=NO1;
Writeln('Object property : ');
PI:=GetPropInfo(O,'ObjField');
Write('Property class : ');
Writeln(GetObjectPropClass(O,'ObjField').ClassName);
Write('Value : ');
Writeln((O.ObjField as TNamedObject).ObjectName);
Write('Get (name) : ');
Writeln((GetObjectProp(O,'ObjField') As TNamedObject).ObjectName);
Write('Get (propinfo) : ');
Writeln((GetObjectProp(O,PI,TObject) as TNamedObject).ObjectName);
SetObjectProp(O,'ObjField',NO2);
Write('Set (name,NO2) : ');
Writeln((O.ObjField as TNamedObject).ObjectName);
SetObjectProp(O,PI,NO1);
Write('Set (propinfo,NO1) : ');
Writeln((O.ObjField as TNamedObject).ObjectName);
O.Free;
end.
FPC 3.2.2 i386-win32-win32/win64
a ) getobjectprop.lpr(7,6) Fatal: Cannot find rttiobj used by getobjectprop of the Project Inspector.
If i change the uses to rtti, RttiUtils, typeinfo it compiles a little more
b ) getobjectprop.lpr(11,7) Error: Identifier not found "TMyTestObject"
Compile Project, Target: getobjectprop.exe: Exit code 1, Errors: 15, Warnings: 1, Hints: 7
Hint: Start of reading config file X:\xxxx\fpc\bin\i386-win32\fpc.cfg
Hint: End of reading config file X:\xxxx\fpc\bin\i386-win32\fpc.cfg
Verbose: Free Pascal Compiler version 3.2.2-rrelease_3_2_2-0-g0d122c4953 [2021/11/24] for i386
Verbose: Copyright (c) 1993-2021 by Florian Klaempfl and others
Verbose: Target OS: Win32 for i386
Verbose: Compiling getobjectprop.lpr
getobjectprop.lpr(8,6) Warning: Unit "Rtti" is experimental
getobjectprop.lpr(11,7) Error: Identifier not found "TMyTestObject"
getobjectprop.lpr(11,20) Error: Error in type definition
getobjectprop.lpr(13,13) Error: Identifier not found "TNamedObject"
getobjectprop.lpr(13,25) Error: Error in type definition
getobjectprop.lpr(16,6) Error: Identifier not found "TMyTestObject"
getobjectprop.lpr(17,8) Error: Identifier not found "TNamedObject"
getobjectprop.lpr(18,7) Error: Illegal qualifier
getobjectprop.lpr(19,8) Error: Identifier not found "TNamedObject"
getobjectprop.lpr(20,7) Error: Illegal qualifier
getobjectprop.lpr(21,5) Error: Illegal qualifier
getobjectprop.lpr(23,20) Error: Incompatible type for arg no. 1: Got "<erroneous type>", expected "TClass"
typinfo.pp(1347,10) Hint: Found declaration: GetPropInfo(TClass;const AnsiString):^TPropInfo;
typinfo.pp(1341,10) Hint: Found declaration: GetPropInfo(TObject;const AnsiString):^TPropInfo;
typinfo.pp(1289,10) Hint: Found declaration: GetPropInfo(PTypeInfo;const AnsiString):^TPropInfo;
getobjectprop.lpr(25,31) Error: Incompatible type for arg no. 1: Got "<erroneous type>", expected "TClass"
typinfo.pp(1983,11) Hint: Found declaration: GetObjectPropClass(TClass;const AnsiString):Class Of TObject;
typinfo.pp(1977,10) Hint: Found declaration: GetObjectPropClass(TObject;const AnsiString):Class Of TObject;
getobjectprop.lpr(27,14) Error: Illegal qualifier
getobjectprop.lpr(27,26) Error: Identifier not found "TNamedObject"
getobjectprop.lpr(29,25) Fatal: Syntax error, "." expected but "(" found
Verbose: Compilation aborted
Verbose: X:\xxxx\fpc\bin\i386-win32\ppc386.exe returned an error exitcode