fpc/tests/test/tcustomattr10.pp
svenbarth e97a2cb03e * tests with Delphi showed that an attribute class must explicitely declare a parameterless constructor if it should be used, cause TCustomAttribute.Create is private
Note: this also means that TCustomAttribute itself can not be used as an attribute
* adjusted existing tests
+ added test

git-svn-id: trunk@42471 -
2019-07-20 20:03:38 +00:00

43 lines
684 B
ObjectPascal

program tcustomattr10;
{$mode objfpc}{$H+}
{$modeswitch prefixedattributes}
uses
typinfo;
type
{ TMyAttr }
TMyAttrAttribute = class(TCustomAttribute)
constructor Create;
end;
type
// The attribute should be also accessable without the Attribute suffix.
[TMyAttr]
TMyObject = class(TObject)
end;
constructor TMyAttrAttribute.Create;
begin
end;
var
at: PAttributeTable;
AClassAttribute: TCustomAttribute;
begin
at := GetAttributeTable(TMyObject.ClassInfo);
if not Assigned(at) then
Halt(1);
if at^.AttributeCount<>1 then
halt(2);
AClassAttribute := GetAttribute(at,0);
if AClassAttribute = nil then
halt(3);
writeln('ok');
end.