66interface
77
88uses
9- Types,
9+ System.Types,
10+ System.Classes,
1011 DUnitX.TestFramework,
1112 PythonEngine,
1213 WrapDelphi;
@@ -35,6 +36,7 @@ TTestRecord = record
3536
3637 TFruitDynArray = TArray<TFruit>;
3738 TStaticArray = array [0 ..999 ] of Int64;
39+
3840 TTestRttiAccess = class
3941 private
4042 FFruit: TFruit;
@@ -58,6 +60,7 @@ TTestRttiAccess = class
5860 function SetStringField (var Value : Integer): string; overload;
5961 function SetStringField (const Value : string): string; overload;
6062 procedure PassVariantArray (const Value : Variant);
63+ function ClassRefParam (ClassRef: TPersistentClass): string;
6164 end ;
6265
6366 TTestInterfaceImpl = class (TInterfacedObject, ITestInterface)
@@ -122,14 +125,15 @@ TTestWrapDelphi = class(TObject)
122125 procedure TestFreeReturnedObject ;
123126 [Test]
124127 procedure TestPassVariantArray ;
128+ [Test]
129+ procedure TestClassRefParam ;
125130 end ;
126131
127132implementation
128133
129134Uses
130135 System.SysUtils,
131136 System.Variants,
132- System.Classes,
133137 System.Rtti,
134138 VarPyth,
135139 WrapDelphiClasses;
@@ -201,7 +205,7 @@ procedure TTestWrapDelphi.SetupFixture;
201205 Py := PyDelphiWrapper.WrapInterface(TValue.From(FTestInterface));
202206 DelphiModule.SetVar(' rtti_interface' , Py);
203207 PythonEngine.Py_DecRef(Py);
204- PythonEngine.ExecString(' from delphi import rtti_var, rtti_rec, rtti_interface' );
208+ PythonEngine.ExecString(' from delphi import rtti_var, rtti_rec, rtti_interface, Object, Collection, Strings ' );
205209 Rtti_Var := MainModule.rtti_var;
206210 Rtti_Rec := MainModule.rtti_rec;
207211 Rtti_Interface := MainModule.rtti_interface;
@@ -218,6 +222,16 @@ procedure TTestWrapDelphi.TearDownFixture;
218222 TestRttiAccess.Free;
219223end ;
220224
225+ procedure TTestWrapDelphi.TestClassRefParam ;
226+ begin
227+ Assert.AreEqual<string>(Rtti_Var.ClassRefParam(MainModule.Collection), ' TCollection' );
228+ Assert.AreEqual<string>(Rtti_Var.ClassRefParam(MainModule.Strings), ' TStrings' );
229+ Assert.WillRaise(procedure
230+ begin
231+ Rtti_Var.ClassRefParam(MainModule.Object )
232+ end );
233+ end ;
234+
221235procedure TTestWrapDelphi.TestDoubleField ;
222236begin
223237 TestRttiAccess.DoubleField := 3.14 ;
@@ -442,6 +456,11 @@ function TTestRttiAccess.SetStringField(var Value: Integer): string;
442456 Result := StringField;
443457end ;
444458
459+ function TTestRttiAccess.ClassRefParam (ClassRef: TPersistentClass): string;
460+ begin
461+ Result := ClassRef.ClassName;
462+ end ;
463+
445464function TTestRttiAccess.GetData : TObject;
446465begin
447466 Result := TStringList.Create;
0 commit comments