Skip to content

Commit 320f920

Browse files
authored
Merge pull request #71 from Embarcadero/prmerge
Partially merging #7
2 parents d12ea0b + 679e712 commit 320f920

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Source/WrapDelphi.pas

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,7 @@ TPyDelphiWrapper = class(TEngineClient, IFreeNotificationSubscriber)
939939
procedure Finalize; override;
940940
procedure DefineVar(const AName : string; const AValue : Variant); overload;
941941
procedure DefineVar(const AName : string; AValue : TObject); overload;
942+
procedure DefineVar(const AName : string; AValue : TClass); overload;
942943
procedure RegisterDelphiWrapper(AWrapperClass : TPyDelphiObjectClass);
943944
function RegisterHelperType(APyObjectClass : TPyObjectClass) : TPythonType;
944945
function RegisterFunction(AFuncName : PAnsiChar; AFunc : PyCFunction; ADocString : PAnsiChar ): PPyMethodDef; overload;
@@ -2968,6 +2969,8 @@ function GetRttiAttr(ParentAddr: Pointer; ParentType: TRttiStructuredType;
29682969
case Prop.PropertyType.TypeKind of
29692970
tkClass:
29702971
Result := PyDelphiWrapper.Wrap(Prop.GetValue(ParentAddr).AsObject);
2972+
tkClassRef:
2973+
Result := PyDelphiWrapper.WrapClass(Prop.GetValue(ParentAddr).AsClass);
29712974
tkInterface:
29722975
Result := PyDelphiWrapper.WrapInterface(Prop.GetValue(ParentAddr));
29732976
tkMethod:
@@ -2991,6 +2994,8 @@ function GetRttiAttr(ParentAddr: Pointer; ParentType: TRttiStructuredType;
29912994
case Field.FieldType.TypeKind of
29922995
tkClass:
29932996
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
29942999
tkInterface:
29953000
Result := PyDelphiWrapper.WrapInterface(Field.GetValue(ParentAddr));
29963001
tkRecord:
@@ -3021,6 +3026,7 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType
30213026
Field: TRttiField;
30223027
V: TValue;
30233028
Obj: TObject;
3029+
Cls: TClass;
30243030
ValueOut: TValue;
30253031
begin
30263032
Result := False;
@@ -3041,6 +3047,11 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType
30413047
Prop.SetValue(ParentAddr, Obj);
30423048
Result := True;
30433049
end;
3050+
tkClassRef:
3051+
if ValidateClassRef(Value, Prop.PropertyType.Handle, Cls, ErrMsg) then begin
3052+
Prop.SetValue(ParentAddr, Cls);
3053+
Result := True;
3054+
end;
30443055
tkInterface:
30453056
if ValidateInterfaceProperty(Value, Prop.PropertyType as TRttiInterfaceType, ValueOut, ErrMsg) then begin
30463057
Prop.SetValue(ParentAddr, ValueOut);
@@ -3086,6 +3097,11 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType
30863097
Field.SetValue(ParentAddr, Obj);
30873098
Result := True;
30883099
end;
3100+
tkClassRef:
3101+
if ValidateClassRef(value, Field.FieldType.Handle, Cls, ErrMsg) then begin
3102+
Field.SetValue(ParentAddr, Cls);
3103+
Result := True;
3104+
end;
30893105
tkInterface:
30903106
if ValidateInterfaceProperty(Value, Field.FieldType as TRttiInterfaceType, ValueOut, ErrMsg) then begin
30913107
Field.SetValue(ParentAddr, ValueOut);
@@ -4952,6 +4968,16 @@ procedure TPyDelphiWrapper.DefineVar(const AName: string; AValue: TObject);
49524968
Engine.Py_DECREF(_obj);
49534969
end;
49544970

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+
49554981
destructor TPyDelphiWrapper.Destroy;
49564982
begin
49574983
UnsubscribeFreeNotifications;

0 commit comments

Comments
 (0)