diff --git a/Source/WrapDelphi.pas b/Source/WrapDelphi.pas index b3c4e350..4b7b45fe 100644 --- a/Source/WrapDelphi.pas +++ b/Source/WrapDelphi.pas @@ -939,6 +939,7 @@ TPyDelphiWrapper = class(TEngineClient, IFreeNotificationSubscriber) procedure Finalize; override; procedure DefineVar(const AName : string; const AValue : Variant); overload; procedure DefineVar(const AName : string; AValue : TObject); overload; + procedure DefineVar(const AName : string; AValue : TClass); overload; procedure RegisterDelphiWrapper(AWrapperClass : TPyDelphiObjectClass); function RegisterHelperType(APyObjectClass : TPyObjectClass) : TPythonType; function RegisterFunction(AFuncName : PAnsiChar; AFunc : PyCFunction; ADocString : PAnsiChar ): PPyMethodDef; overload; @@ -2968,6 +2969,8 @@ function GetRttiAttr(ParentAddr: Pointer; ParentType: TRttiStructuredType; case Prop.PropertyType.TypeKind of tkClass: Result := PyDelphiWrapper.Wrap(Prop.GetValue(ParentAddr).AsObject); + tkClassRef: + Result := PyDelphiWrapper.WrapClass(Prop.GetValue(ParentAddr).AsClass); tkInterface: Result := PyDelphiWrapper.WrapInterface(Prop.GetValue(ParentAddr)); tkMethod: @@ -2991,6 +2994,8 @@ function GetRttiAttr(ParentAddr: Pointer; ParentType: TRttiStructuredType; case Field.FieldType.TypeKind of tkClass: Result := PyDelphiWrapper.Wrap(Field.GetValue(ParentAddr).AsObject); // Returns None if Field is nil + tkClassRef: + Result := PyDelphiWrapper.WrapClass(Field.GetValue(ParentAddr).AsClass); // Returns None if Field is nil tkInterface: Result := PyDelphiWrapper.WrapInterface(Field.GetValue(ParentAddr)); tkRecord: @@ -3021,6 +3026,7 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType Field: TRttiField; V: TValue; Obj: TObject; + Cls: TClass; ValueOut: TValue; begin Result := False; @@ -3041,6 +3047,11 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType Prop.SetValue(ParentAddr, Obj); Result := True; end; + tkClassRef: + if ValidateClassRef(Value, Prop.PropertyType.Handle, Cls, ErrMsg) then begin + Prop.SetValue(ParentAddr, Cls); + Result := True; + end; tkInterface: if ValidateInterfaceProperty(Value, Prop.PropertyType as TRttiInterfaceType, ValueOut, ErrMsg) then begin Prop.SetValue(ParentAddr, ValueOut); @@ -3086,6 +3097,11 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType Field.SetValue(ParentAddr, Obj); Result := True; end; + tkClassRef: + if ValidateClassRef(value, Field.FieldType.Handle, Cls, ErrMsg) then begin + Field.SetValue(ParentAddr, Cls); + Result := True; + end; tkInterface: if ValidateInterfaceProperty(Value, Field.FieldType as TRttiInterfaceType, ValueOut, ErrMsg) then begin Field.SetValue(ParentAddr, ValueOut); @@ -4952,6 +4968,16 @@ procedure TPyDelphiWrapper.DefineVar(const AName: string; AValue: TObject); Engine.Py_DECREF(_obj); end; +procedure TPyDelphiWrapper.DefineVar(const AName: string; AValue: TClass); +var + LObj: PPyObject; +begin + Assert(Assigned(Module)); + LObj := WrapClass(AValue); + Module.SetVar(AnsiString(AName), LObj); + Engine.Py_DECREF(LObj); +end; + destructor TPyDelphiWrapper.Destroy; begin UnsubscribeFreeNotifications;