tcustomattr6.pp 671 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. program tcustomattr6;
  2. {$mode objfpc}{$H+}
  3. {$modeswitch prefixedattributes}
  4. uses
  5. typinfo;
  6. type
  7. { tmyt }
  8. TMyt = class(TCustomAttribute)
  9. constructor create;
  10. end;
  11. type
  12. { TMyObject }
  13. TMyObject = class(TObject)
  14. private
  15. FInt: integer;
  16. published
  17. [TMyt]
  18. property PublicInt: integer read FInt;
  19. end;
  20. constructor TMyt.create;
  21. begin
  22. end;
  23. var
  24. pi: PPropInfo;
  25. AClassAttribute: TCustomAttribute;
  26. begin
  27. pi := GetPropInfo(TMyObject.ClassInfo,'PublicInt');
  28. if pi^.AttributeCount<>1 then
  29. halt(1);
  30. AClassAttribute := GetPropAttribute(pi,0) as TCustomAttribute;
  31. if AClassAttribute = nil then
  32. halt(2);
  33. writeln('ok');
  34. end.