tests.rtti.types.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. unit tests.rtti.types;
  2. {$ifdef fpc}
  3. {$mode objfpc}{$H+}
  4. {$modeswitch advancedrecords}
  5. {$endif}
  6. interface
  7. uses
  8. Classes, SysUtils;
  9. Type
  10. {$M+}
  11. TGetClassProperties = class
  12. private
  13. FPubPropRO: integer;
  14. FPubPropRW: integer;
  15. published
  16. property PubPropRO: integer read FPubPropRO;
  17. property PubPropRW: integer read FPubPropRW write FPubPropRW;
  18. property PubPropSetRO: integer read FPubPropRO;
  19. property PubPropSetRW: integer read FPubPropRW write FPubPropRW;
  20. end;
  21. TGetClassPropertiesSub = class(TGetClassProperties)
  22. end;
  23. {$M+}
  24. ITestInterface = interface
  25. procedure Test;
  26. function Test2: LongInt;
  27. procedure Test3(aArg1: LongInt; const aArg2: AnsiString; var aArg3: Boolean; out aArg4: Word);
  28. function Test4(aArg1: array of LongInt; aArg2: array of const): AnsiString;
  29. end;
  30. {$M-}
  31. TManagedRec = record
  32. s: string;
  33. end;
  34. {$ifdef fpc}
  35. TManagedRecOp = record
  36. class operator AddRef(var a: TManagedRecOp);
  37. end;
  38. {$endif}
  39. TNonManagedRec = record
  40. i: Integer;
  41. end;
  42. TManagedObj = object
  43. i: IInterface;
  44. end;
  45. TNonManagedObj = object
  46. d: double;
  47. end;
  48. TTestEnum = (te1, te2, te3, te4, te5);
  49. TTestSet = set of TTestEnum;
  50. TTestProc = procedure;
  51. TTestFunc1 = function: LongInt;
  52. TTestFunc2 = function(aArg1: LongInt; aArg2: array of LongInt): String;
  53. TTestMethod = procedure of object;
  54. TTestMethod1 = function: LongInt of object;
  55. TTestMethod2 = function(aArg1: LongInt; aArg2: array of LongInt): String of object;
  56. TTestHelper = class helper for TObject
  57. end;
  58. TTestRecord = record
  59. Value1: LongInt;
  60. Value2: String;
  61. end;
  62. PTestRecord = ^TTestRecord;
  63. TArrayOfString = array[0..0] of string;
  64. TArrayOfManagedRec = array[0..0] of TManagedRec;
  65. TArrayOfNonManagedRec = array[0..0] of TNonManagedRec;
  66. TArrayOfByte = array[0..0] of byte;
  67. TArrayOfLongintDyn = array of LongInt;
  68. TArrayOfLongintStatic = array[0..3] of LongInt;
  69. TArrayOfLongint2DStatic = array[0..3, 2..4] of LongInt;
  70. TTestDynArray = array of Integer;
  71. TTestEnumeration = (en1, en2, en3, en4);
  72. {$M-}
  73. { TTestValueClass }
  74. {$M+}
  75. TTestValueClass = class
  76. private
  77. FAArray: TTestDynArray;
  78. FAChar: AnsiChar;
  79. FAComp: Comp;
  80. FACurrency: Currency;
  81. FADouble: Double;
  82. FAEnumeration: TTestEnumeration;
  83. FAExtended: Extended;
  84. FAInteger: integer;
  85. FAObject: TObject;
  86. FASingle: Single;
  87. FAString: string;
  88. FABoolean: boolean;
  89. FAShortString: ShortString;
  90. FAUnknown: IUnknown;
  91. FAWideChar: WideChar;
  92. function GetAInteger: integer;
  93. function GetAString: string;
  94. function GetABoolean: boolean;
  95. function GetAShortString: ShortString;
  96. procedure SetWriteOnly(AValue: integer);
  97. published
  98. property AArray: TTestDynArray read FAArray write FAArray;
  99. property AEnumeration: TTestEnumeration read FAEnumeration write FAEnumeration;
  100. property AInteger: Integer read FAInteger write FAInteger;
  101. property AString: string read FAString write FAString;
  102. property ASingle: Single read FASingle write FASingle;
  103. property ADouble: Double read FADouble write FADouble;
  104. property AExtended: Extended read FAExtended write FAExtended;
  105. property ACurrency: Currency read FACurrency write FACurrency;
  106. property AObject: TObject read FAObject write FAObject;
  107. property AUnknown: IUnknown read FAUnknown write FAUnknown;
  108. property AComp: Comp read FAComp write FAComp;
  109. property ABoolean: boolean read FABoolean write FABoolean;
  110. property AShortString: ShortString read FAShortString write FAShortString;
  111. property AGetInteger: Integer read GetAInteger;
  112. property AGetString: string read GetAString;
  113. property AGetBoolean: boolean read GetABoolean;
  114. property AGetShortString: ShortString read GetAShortString;
  115. property AWriteOnly: integer write SetWriteOnly;
  116. property AChar: AnsiChar read FAChar write FAChar;
  117. property AWideChar: WideChar read FAWideChar write FAWideChar;
  118. end;
  119. {$M-}
  120. {$ifdef fpc}
  121. {$PUSH}
  122. {$INTERFACES CORBA}
  123. ICORBATest = interface
  124. end;
  125. {$POP}
  126. {$endif}
  127. implementation
  128. { TTestValueClass }
  129. function TTestValueClass.GetAInteger: integer;
  130. begin
  131. result := FAInteger;
  132. end;
  133. function TTestValueClass.GetAString: string;
  134. begin
  135. result := FAString;
  136. end;
  137. function TTestValueClass.GetABoolean: boolean;
  138. begin
  139. result := FABoolean;
  140. end;
  141. function TTestValueClass.GetAShortString: ShortString;
  142. begin
  143. Result := FAShortString;
  144. end;
  145. procedure TTestValueClass.SetWriteOnly(AValue: integer);
  146. begin
  147. // Do nothing
  148. end;
  149. {$ifdef fpc}
  150. class operator TManagedRecOp.AddRef(var a: TManagedRecOp);
  151. begin
  152. end;
  153. {$endif}
  154. end.