tclassattribute4.pp 803 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. program tclassattribute4;
  2. {$mode delphi}
  3. uses
  4. typinfo;
  5. type
  6. { tmyt }
  7. tmyt = class(TCustomAttribute)
  8. private
  9. FID: integer;
  10. public
  11. constructor create(Id: integer);
  12. end;
  13. type
  14. [Tmyt(924)]
  15. [Tmyt(1425)]
  16. TMyObject = class(TObject)
  17. end;
  18. var
  19. rtd: PAttributeData;
  20. AClassAttribute: tmyt;
  21. { tmyt }
  22. constructor tmyt.create(Id: integer);
  23. begin
  24. Fid := Id;
  25. end;
  26. begin
  27. rtd := GetAttributeData(TMyObject.ClassInfo);
  28. if rtd^.AttributeCount<>2 then
  29. halt(1);
  30. AClassAttribute := GetAttribute(rtd,1) as tmyt;
  31. if AClassAttribute = nil then
  32. halt(2);
  33. if AClassAttribute.FID<>1425 then
  34. halt(3);
  35. AClassAttribute := GetAttribute(rtd,0) as tmyt;
  36. if AClassAttribute = nil then
  37. halt(2);
  38. if AClassAttribute.FID<>924 then
  39. halt(3);
  40. writeln('ok');
  41. end.