ex14.pp 722 B

123456789101112131415161718192021222324252627282930313233
  1. Program example13;
  2. { This program demonstrates the FindPropInfo function }
  3. {$mode objfpc}
  4. uses
  5. rttiobj,typinfo,sysutils;
  6. Var
  7. O : TMyTestObject;
  8. PT : PTypeData;
  9. PI : PPropInfo;
  10. I,J : Longint;
  11. PP : PPropList;
  12. prI : PPropInfo;
  13. begin
  14. O:=TMyTestObject.Create;
  15. PI:=FindPropInfo(O,'BooleanField');
  16. Writeln('FindPropInfo(Instance,BooleanField) : ',PI^.Name);
  17. PI:=FindPropInfo(O.ClassType,'ByteField');
  18. Writeln('FindPropInfo(Class,ByteField) : ',PI^.Name);
  19. Write ('FindPropInfo(Class,NonExistingProp) : ');
  20. Try
  21. PI:=FindPropInfo(O,'NonExistingProp');
  22. except
  23. On E: Exception do
  24. Writeln('Caught exception "',E.ClassName,'" with message : ',E.Message);
  25. end;
  26. O.Free;
  27. end.