testunit.pp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. {$mode objfpc}
  2. {$h+}
  3. unit testunit;
  4. interface
  5. uses SysUtils, Classes;
  6. Const
  7. AnIntegerConst = 1;
  8. AStringConst = 'Hello, World!';
  9. AFLoatconst = 1.23;
  10. ABooleanConst = True;
  11. ATypedConst : Integer = 3;
  12. AnArrayConst : Array[1..3] of Integer = (1,2,3);
  13. ARecordConst : TMethod = (Code:Nil;Data:Nil);
  14. ASetConst = [true,false];
  15. ADeprecatedConst = 1 deprecated;
  16. Type
  17. // an enumerated type
  18. TAnEnumType = (one,two,three);
  19. TASetType = Set of TAnEnumType;
  20. TAnArrayType = Array[1..10] of Integer;
  21. // TASubRangeType = one..two;
  22. TABooleanArrayType = Array[Boolean] of Integer;
  23. TARecordType = Record
  24. X,Y : Integer;
  25. Z : String;
  26. end;
  27. TAVariantRecordType = Record
  28. A : String;
  29. Case Integer of
  30. 1 : (X,Y : Integer);
  31. 2 : (phi,Omega : Real);
  32. end;
  33. TAVariantRecordType2 = Record
  34. A : String;
  35. Case Atype : Integer of
  36. 1 : (X,Y : Integer);
  37. 2 : (phi,Omega : Real);
  38. end;
  39. TADeprecatedType = Integer deprecated;
  40. Var
  41. ASimpleVar : Integer;
  42. ATypedVar : TMethod;
  43. ARecordVar : Record
  44. A,B : integer;
  45. end;
  46. AnArrayVar : Array[1..10] of Integer;
  47. ATypedArray : Array[TanEnumType] of Integer;
  48. AInitVar : Integer = 1;
  49. ADeprecatedVar : Integer deprecated;
  50. ACVarVar : Integer; cvar;
  51. AnExternalVar : Integer; external name 'avar';
  52. AnExternalLibVar : Integer; external 'library' name 'avar';
  53. Procedure SimpleProc;
  54. Procedure OverloadedProc(A : Integer);
  55. Procedure OverloadedProc(B : String);
  56. Function SimpleFunc : Integer;
  57. Function OverloadedFunc(A: Integer) : Integer;
  58. Function OverloadedFunc(B : String) : Integer;
  59. Procedure ConstArgProc(Const A : Integer);
  60. Procedure VarArgProc(Var A : Integer);
  61. Procedure OutArgProc(Out A : Integer);
  62. Procedure UntypedVarArgProc(Var A);
  63. Procedure UntypedConstArgProc(const A);
  64. Procedure UntypedOutArgProc(Out A);
  65. Procedure ArrayArgProc (A : TAnArrayType);
  66. Procedure OpenArrayArgProc(A : Array of string);
  67. Procedure ConstArrayArgProc(A : Array of const);
  68. Procedure externalproc; external;
  69. Procedure externalnameProc; external name 'aname';
  70. Procedure externallibnameProc; external 'alibrary' name 'aname';
  71. Type
  72. { TMyParentClass }
  73. TMyParentClass = Class(TComponent)
  74. Private
  75. FI : Integer;
  76. function GetA(AIndex : Integer): String;
  77. function GetIP(AIndex: integer): String;
  78. procedure SetA(AIndex : Integer; const AValue: String);
  79. procedure SetIP(AIndex: integer; const AValue: String);
  80. Procedure WriteI(AI : Integer);
  81. Function ReadI : Integer;
  82. Protected
  83. Procedure AProtectedMethod;
  84. Property AProtectedProp : Integer Read FI Write FI;
  85. Public
  86. Constructor Create(AOwner : TComponent); override;
  87. Destructor Destroy; override;
  88. Procedure AVirtualProc; virtual;
  89. Procedure AnAbstractProc; virtual; abstract;
  90. Procedure AMessageProc(Var Msg); Message 123;
  91. Procedure AStringMessageProc(Var Msg); Message '123';
  92. Procedure ADeprecatedProc; deprecated;
  93. Procedure APlatformProc; Platform;
  94. Property IntProp : Integer Read FI Write Fi;
  95. Property IntROProp : Integer Read FI;
  96. Property GetIntProp : Integer Read ReadI Write WriteI;
  97. Property AnArrayProp[AIndex : Integer] : String Read GetA write SetA;
  98. Property AnIndexProp : String Index 1 Read GetIP Write SetIP;
  99. Property AnIndexProp2 : String Index 2 Read GetIP Write SetIP;
  100. Published
  101. Procedure SomePublishedMethod;
  102. end;
  103. { TMyChildClass }
  104. TMyChildClass = Class(TMyParentClass)
  105. Public
  106. Procedure AVirtualProc; Override;
  107. Procedure AnAbstractProc; Override;
  108. Published
  109. Property AProtectedProp;
  110. end;
  111. Implementation
  112. Procedure SimpleProc;
  113. begin
  114. end;
  115. Procedure OverloadedProc(A : Integer);
  116. begin
  117. end;
  118. Procedure OverloadedProc(B : String);
  119. begin
  120. end;
  121. Function SimpleFunc : Integer;
  122. begin
  123. end;
  124. Function OverloadedFunc(A: Integer) : Integer;
  125. begin
  126. end;
  127. Function OverloadedFunc(B : String) : Integer;
  128. begin
  129. end;
  130. Procedure ArrayArgProc (A : TAnArrayType);
  131. begin
  132. end;
  133. Procedure OpenArrayArgProc(A : Array of string);
  134. begin
  135. end;
  136. Procedure ConstArrayArgProc(A : Array of const);
  137. begin
  138. end;
  139. Procedure ConstArgProc(Const A : Integer);
  140. begin
  141. end;
  142. Procedure VarArgProc(Var A : Integer);
  143. begin
  144. end;
  145. Procedure OutArgProc(Out A : Integer);
  146. begin
  147. end;
  148. Procedure UntypedVarArgProc(Var A);
  149. begin
  150. end;
  151. Procedure UntypedConstArgProc(const A);
  152. begin
  153. end;
  154. Procedure UntypedOutArgProc(Out A);
  155. begin
  156. end;
  157. { TMyChildClass }
  158. procedure TMyChildClass.AVirtualProc;
  159. begin
  160. inherited AVirtualProc;
  161. end;
  162. procedure TMyChildClass.AnAbstractProc;
  163. begin
  164. // Cannot call ancestor
  165. end;
  166. { TMyParentClass }
  167. procedure TMyParentClass.WriteI(AI: Integer);
  168. begin
  169. end;
  170. function TMyParentClass.GetA(AIndex : Integer): String;
  171. begin
  172. end;
  173. function TMyParentClass.GetIP(AIndex: integer): String;
  174. begin
  175. end;
  176. procedure TMyParentClass.SetA(AIndex : Integer; const AValue: String);
  177. begin
  178. end;
  179. procedure TMyParentClass.SetIP(AIndex: integer; const AValue: String);
  180. begin
  181. end;
  182. function TMyParentClass.ReadI: Integer;
  183. begin
  184. end;
  185. procedure TMyParentClass.AProtectedMethod;
  186. begin
  187. end;
  188. constructor TMyParentClass.Create(AOwner: TComponent);
  189. begin
  190. inherited Create(AOwner);
  191. end;
  192. destructor TMyParentClass.Destroy;
  193. begin
  194. inherited Destroy;
  195. end;
  196. procedure TMyParentClass.AVirtualProc;
  197. begin
  198. end;
  199. procedure TMyParentClass.AMessageProc(var Msg);
  200. begin
  201. end;
  202. procedure TMyParentClass.AStringMessageProc(var Msg);
  203. begin
  204. end;
  205. procedure TMyParentClass.ADeprecatedProc;
  206. begin
  207. end;
  208. procedure TMyParentClass.APlatformProc;
  209. begin
  210. end;
  211. procedure TMyParentClass.SomePublishedMethod;
  212. begin
  213. end;
  214. end.