tclassattribute10.pp 572 B

12345678910111213141516171819202122232425262728293031323334
  1. program tclassattribute10;
  2. {$mode objfpc}{$H+}
  3. {$modeswitch prefixedattributes}
  4. uses
  5. typinfo;
  6. type
  7. { TMyAttr }
  8. TMyAttrAttribute = class(TCustomAttribute)
  9. end;
  10. type
  11. // The attribute should be also accessable without the Attribute suffix.
  12. [TMyAttr]
  13. TMyObject = class(TObject)
  14. end;
  15. var
  16. ad: PAttributeData;
  17. AClassAttribute: TCustomAttribute;
  18. begin
  19. ad := GetAttributeData(TMyObject.ClassInfo);
  20. if ad^.AttributeCount<>1 then
  21. halt(1);
  22. AClassAttribute := GetAttribute(ad,0);
  23. if AClassAttribute = nil then
  24. halt(2);
  25. writeln('ok');
  26. end.