Recent

Author Topic: GetObjectProp: Sample from rtl documentation not running  (Read 551 times)

af0815

  • Hero Member
  • *****
  • Posts: 1168
GetObjectProp: Sample from rtl documentation not running
« on: January 26, 2023, 11:52:39 am »
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.html
Code: Pascal  [Select][+][-]
  1. program example5;
  2.  
  3. { This program demonstrates the GetObjectProp function }
  4.  
  5. {$mode objfpc}
  6.  
  7. uses rttiobj,typinfo;
  8.  
  9. Var
  10.   O : TMyTestObject;
  11.   PI : PPropInfo;
  12.   NO1,NO2 : TNamedObject;
  13.  
  14. begin
  15.   O:=TMyTestObject.Create;
  16.   NO1:=TNamedObject.Create;
  17.   NO1.ObjectName:='First named object';
  18.   NO2:=TNamedObject.Create;
  19.   NO2.ObjectName:='Second named object';
  20.   O.ObjField:=NO1;
  21.   Writeln('Object property : ');
  22.   PI:=GetPropInfo(O,'ObjField');
  23.   Write('Property class     : ');
  24.   Writeln(GetObjectPropClass(O,'ObjField').ClassName);
  25.   Write('Value              : ');
  26.   Writeln((O.ObjField as TNamedObject).ObjectName);
  27.   Write('Get (name)         : ');
  28.   Writeln((GetObjectProp(O,'ObjField') As TNamedObject).ObjectName);
  29.   Write('Get (propinfo)     : ');
  30.   Writeln((GetObjectProp(O,PI,TObject) as TNamedObject).ObjectName);
  31.   SetObjectProp(O,'ObjField',NO2);
  32.   Write('Set (name,NO2)     : ');
  33.   Writeln((O.ObjField as TNamedObject).ObjectName);
  34.   SetObjectProp(O,PI,NO1);
  35.   Write('Set (propinfo,NO1) : ');
  36.   Writeln((O.ObjField as TNamedObject).ObjectName);
  37.   O.Free;
  38. 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"

Quote
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



regards
Andreas

Thaddy

  • Hero Member
  • *****
  • Posts: 12934
Re: GetObjectProp: Sample from rtl documentation not running
« Reply #1 on: January 26, 2023, 02:05:30 pm »
See https://gitlab.com/freepascal.org/fpc/documentation/-/issues/13199 which is closed.
rttiobj is in the docs, probably as per Florian's remark.
In memory of Gordon Moore  (January 3, 1929 – March 24, 2023) Just double the heaven every two years from now.

af0815

  • Hero Member
  • *****
  • Posts: 1168
Re: GetObjectProp: Sample from rtl documentation not running
« Reply #2 on: January 26, 2023, 02:44:46 pm »
Thaddy, there is more wrong and your issue linked is 13 yrs old and the sample is wrong from start to end. If some units exist anywhere in the doc sources is nice, but the sample is broken, because it reference to not existing code in a standard source install of fpc. And in the sample code is NO HINT where the missing code is.

All GetxxxProp samples (for typinfo.pp) looks broken in the same manner in the official documentation.

Edit: https://gitlab.com/freepascal.org/fpc/documentation/-/blob/main/examples/typinfex/rttiobj.pp
« Last Edit: January 26, 2023, 02:48:28 pm by af0815 »
regards
Andreas

PascalDragon

  • Hero Member
  • *****
  • Posts: 4968
  • Compiler Developer
Re: GetObjectProp: Sample from rtl documentation not running
« Reply #3 on: January 26, 2023, 09:14:35 pm »
I am searching for information and found samples in the rtl documentation, but i am not able to run the samples

The samples contained in the documentation are not necessarily meant to be completely usable or even compileable. They simply illustrate the principles of what is documented.

af0815

  • Hero Member
  • *****
  • Posts: 1168
Re: GetObjectProp: Sample from rtl documentation not running
« Reply #4 on: January 26, 2023, 10:50:27 pm »
Then it should marked: "THIS SAMPLE IS NOT COMPLETE" look in the source of the docs

The main functionality of the sample is in the not shown code. IMHO not a good style.
« Last Edit: January 26, 2023, 10:55:56 pm by af0815 »
regards
Andreas

 

TinyPortal © 2005-2018