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