tcustomattr11.pp 626 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. program tcustomattr11;
  2. {$mode objfpc}
  3. {$modeswitch prefixedattributes}
  4. uses
  5. TypInfo;
  6. type
  7. TTest = class(TCustomAttribute)
  8. end;
  9. TTestAttribute = class(TCustomAttribute)
  10. end;
  11. { the attribute with the Attribute suffix is preferred }
  12. [TTest]
  13. TTestObj = class
  14. end;
  15. var
  16. ad: PAttributeData;
  17. attr: TCustomAttribute;
  18. begin
  19. ad := GetAttributeData(TypeInfo(TTestObj));
  20. if not Assigned(ad) then
  21. Halt(1);
  22. if ad^.AttributeCount <> 1 then
  23. Halt(2);
  24. attr := GetAttribute(ad, 0);
  25. if not Assigned(attr) then
  26. Halt(3);
  27. if not (attr is TTestAttribute) then
  28. Halt(4);
  29. Writeln('ok');
  30. end.