Skip to content

Partially merging #7 #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Source/WrapDelphi.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -3021,6 +3026,7 @@ function SetRttiAttr(const ParentAddr: Pointer; ParentType: TRttiStructuredType
Field: TRttiField;
V: TValue;
Obj: TObject;
Cls: TClass;
ValueOut: TValue;
begin
Result := False;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down