tismngd1.pp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. program tismngd1;
  2. {$mode objfpc}
  3. {$modeswitch advancedrecords}
  4. uses
  5. TypInfo;
  6. var
  7. gError: LongInt = 0;
  8. function NextErrorCode: LongInt; inline;
  9. begin
  10. Inc(gError);
  11. Result := gError;
  12. end;
  13. generic procedure TestType<T>(aIsMngd: Boolean); inline;
  14. begin
  15. if IsManagedType(T) <> aIsMngd then begin
  16. Writeln('IsManagedType(', PTypeInfo(TypeInfo(T))^.Name, ') failure; expected: ', aIsMngd, ', got: ', IsManagedType(T));
  17. Halt(NextErrorCode);
  18. end;
  19. NextErrorCode;
  20. end;
  21. type
  22. TTestLongInt = record
  23. a: LongInt;
  24. end;
  25. TTestAnsiString = record
  26. a: AnsiString;
  27. end;
  28. TTestManaged = record
  29. a: LongInt;
  30. class operator Initialize(var aTestManaged: TTestManaged);
  31. end;
  32. TTestObj = object
  33. a: LongInt;
  34. end;
  35. TTestObjAnsiString = object
  36. a: AnsiString;
  37. end;
  38. class operator TTestManaged.Initialize(var aTestManaged: TTestManaged);
  39. begin
  40. aTestManaged.a := 42;
  41. end;
  42. type
  43. TProcVar = procedure;
  44. TMethodVar = procedure of object;
  45. TDynArrayLongInt = array of LongInt;
  46. TStaticArrayLongInt = array[0..4] of LongInt;
  47. TStaticArrayAnsiString = array[0..4] of AnsiString;
  48. TEnum = (eOne, eTwo, eThree);
  49. TSet = set of (sOne, sTwo, sThree);
  50. begin
  51. specialize TestType<LongInt>(False);
  52. specialize TestType<Boolean>(False);
  53. specialize TestType<ShortString>(False);
  54. specialize TestType<AnsiString>(True);
  55. specialize TestType<UnicodeString>(True);
  56. specialize TestType<WideString>(True);
  57. specialize TestType<Single>(False);
  58. specialize TestType<TProcVar>(False);
  59. specialize TestType<TMethodVar>(False);
  60. specialize TestType<Pointer>(False);
  61. specialize TestType<IInterface>(True);
  62. specialize TestType<TObject>(False);
  63. specialize TestType<TTestLongInt>(False);
  64. specialize TestType<TTestAnsiString>(True);
  65. specialize TestType<TTestManaged>(True);
  66. specialize TestType<TTestObj>(False);
  67. specialize TestType<TTestObjAnsiString>(True);
  68. specialize TestType<TDynArrayLongInt>(True);
  69. specialize TestType<TStaticArrayLongInt>(False);
  70. specialize TestType<TStaticArrayAnsiString>(True);
  71. specialize TestType<TEnum>(False);
  72. specialize TestType<TSet>(False);
  73. Writeln('Ok');
  74. end.