@@ -939,6 +939,7 @@ TPyDelphiWrapper = class(TEngineClient, IFreeNotificationSubscriber)
939
939
procedure Finalize ; override;
940
940
procedure DefineVar (const AName : string; const AValue : Variant); overload;
941
941
procedure DefineVar (const AName : string; AValue : TObject); overload;
942
+ procedure DefineVar (const AName : string; AValue : TClass); overload;
942
943
procedure RegisterDelphiWrapper (AWrapperClass : TPyDelphiObjectClass);
943
944
function RegisterHelperType (APyObjectClass : TPyObjectClass) : TPythonType;
944
945
function RegisterFunction (AFuncName : PAnsiChar; AFunc : PyCFunction; ADocString : PAnsiChar ): PPyMethodDef; overload;
@@ -2968,6 +2969,8 @@ function GetRttiAttr(ParentAddr: Pointer; ParentType: TRttiStructuredType;
2968
2969
case Prop.PropertyType.TypeKind of
2969
2970
tkClass:
2970
2971
Result := PyDelphiWrapper.Wrap(Prop.GetValue(ParentAddr).AsObject);
2972
+ tkClassRef:
2973
+ Result := PyDelphiWrapper.WrapClass(Prop.GetValue(ParentAddr).AsClass);
2971
2974
tkInterface:
2972
2975
Result := PyDelphiWrapper.WrapInterface(Prop.GetValue(ParentAddr));
2973
2976
tkMethod:
@@ -2991,6 +2994,8 @@ function GetRttiAttr(ParentAddr: Pointer; ParentType: TRttiStructuredType;
2991
2994
case Field.FieldType.TypeKind of
2992
2995
tkClass:
2993
2996
Result := PyDelphiWrapper.Wrap(Field.GetValue(ParentAddr).AsObject); // Returns None if Field is nil
2997
+ tkClassRef:
2998
+ Result := PyDelphiWrapper.WrapClass(Field.GetValue(ParentAddr).AsClass); // Returns None if Field is nil
2994
2999
tkInterface:
2995
3000
Result := PyDelphiWrapper.WrapInterface(Field.GetValue(ParentAddr));
2996
3001
tkRecord:
@@ -3021,6 +3026,7 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType
3021
3026
Field: TRttiField;
3022
3027
V: TValue;
3023
3028
Obj: TObject;
3029
+ Cls: TClass;
3024
3030
ValueOut: TValue;
3025
3031
begin
3026
3032
Result := False;
@@ -3041,6 +3047,11 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType
3041
3047
Prop.SetValue(ParentAddr, Obj);
3042
3048
Result := True;
3043
3049
end ;
3050
+ tkClassRef:
3051
+ if ValidateClassRef(Value , Prop.PropertyType.Handle, Cls, ErrMsg) then begin
3052
+ Prop.SetValue(ParentAddr, Cls);
3053
+ Result := True;
3054
+ end ;
3044
3055
tkInterface:
3045
3056
if ValidateInterfaceProperty(Value , Prop.PropertyType as TRttiInterfaceType, ValueOut, ErrMsg) then begin
3046
3057
Prop.SetValue(ParentAddr, ValueOut);
@@ -3086,6 +3097,11 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType
3086
3097
Field.SetValue(ParentAddr, Obj);
3087
3098
Result := True;
3088
3099
end ;
3100
+ tkClassRef:
3101
+ if ValidateClassRef(value , Field.FieldType.Handle, Cls, ErrMsg) then begin
3102
+ Field.SetValue(ParentAddr, Cls);
3103
+ Result := True;
3104
+ end ;
3089
3105
tkInterface:
3090
3106
if ValidateInterfaceProperty(Value , Field.FieldType as TRttiInterfaceType, ValueOut, ErrMsg) then begin
3091
3107
Field.SetValue(ParentAddr, ValueOut);
@@ -4952,6 +4968,16 @@ procedure TPyDelphiWrapper.DefineVar(const AName: string; AValue: TObject);
4952
4968
Engine.Py_DECREF(_obj);
4953
4969
end ;
4954
4970
4971
+ procedure TPyDelphiWrapper.DefineVar (const AName: string; AValue: TClass);
4972
+ var
4973
+ LObj: PPyObject;
4974
+ begin
4975
+ Assert(Assigned(Module ));
4976
+ LObj := WrapClass(AValue);
4977
+ Module .SetVar(AnsiString(AName), LObj);
4978
+ Engine.Py_DECREF(LObj);
4979
+ end ;
4980
+
4955
4981
destructor TPyDelphiWrapper.Destroy;
4956
4982
begin
4957
4983
UnsubscribeFreeNotifications;
0 commit comments