@@ -31,6 +31,8 @@ TPyDelphiControl = class (TPyDelphiComponent)
3131 // Property Getters
3232 function Get_Parent ( AContext : Pointer) : PPyObject; cdecl;
3333 function Get_Visible (AContext: Pointer): PPyObject; cdecl;
34+ function Get_ControlsCount ( AContext : Pointer) : PPyObject; cdecl;
35+ function Get_Controls (AContext: Pointer): PPyObject; cdecl;
3436 // Property Setters
3537 function Set_Parent ( AValue : PPyObject; AContext : Pointer) : integer; cdecl;
3638 function Set_Visible (AValue: PPyObject; AContext: Pointer): integer; cdecl;
@@ -42,6 +44,24 @@ TPyDelphiControl = class (TPyDelphiComponent)
4244 property DelphiObject: TControl read GetDelphiObject write SetDelphiObject;
4345 end ;
4446
47+ {
48+ Access to the child controls of a FMX.Controls.TControl.Controls collection.
49+ }
50+ TControlsAccess = class (TContainerAccess)
51+ private
52+ function GetContainer : TControl;
53+ public
54+ function GetItem (AIndex : Integer) : PPyObject; override;
55+ function GetSize : Integer; override;
56+ function IndexOf (AValue : PPyObject) : Integer; override;
57+
58+ class function ExpectedContainerClass : TClass; override;
59+ class function SupportsIndexOf : Boolean; override;
60+ class function Name : string; override;
61+
62+ property Container : TControl read GetContainer;
63+ end ;
64+
4565implementation
4666
4767uses
@@ -100,6 +120,20 @@ function TPyDelphiControl.GetDelphiObject: TControl;
100120 Result := TControl(inherited DelphiObject);
101121end ;
102122
123+ function TPyDelphiControl.Get_ControlsCount (AContext: Pointer): PPyObject;
124+ begin
125+ Adjust(@Self);
126+ Result := GetPythonEngine.PyLong_FromLong(DelphiObject.ControlsCount);
127+ end ;
128+
129+ function TPyDelphiControl.Get_Controls (AContext: Pointer): PPyObject;
130+ begin
131+ Adjust(@Self);
132+ Result := Self.PyDelphiWrapper.DefaultContainerType.CreateInstance;
133+ with PythonToDelphi(Result) as TPyDelphiContainer do
134+ Setup(Self.PyDelphiWrapper, TControlsAccess.Create(Self.PyDelphiWrapper, Self.DelphiObject));
135+ end ;
136+
103137function TPyDelphiControl.Get_Parent (AContext: Pointer): PPyObject;
104138begin
105139 Adjust(@Self);
@@ -119,6 +153,10 @@ class procedure TPyDelphiControl.RegisterGetSets(PythonType: TPythonType);
119153 ' Returns/Sets the Control Visibility' , nil );
120154 PythonType.AddGetSet(' Visible' , @TPyDelphiControl.Get_Visible, @TPyDelphiControl.Set_Visible,
121155 ' Returns/Sets the Control Visibility' , nil );
156+ PythonType.AddGetSet(' ControlsCount' , @TPyDelphiControl.Get_ControlsCount, nil ,
157+ ' Returns the count of contained controls' , nil );
158+ PythonType.AddGetSet(' Controls' , @TPyDelphiControl.Get_Controls, nil ,
159+ ' Returns an iterator over contained controls' , nil );
122160end ;
123161
124162class procedure TPyDelphiControl.RegisterMethods (PythonType: TPythonType);
@@ -259,6 +297,72 @@ procedure TControlsRegistration.RegisterWrappers(
259297 APyDelphiWrapper.RegisterDelphiWrapper(TPyDelphiControl);
260298end ;
261299
300+ { TControlsAccess }
301+
302+ class function TControlsAccess.ExpectedContainerClass : TClass;
303+ begin
304+ Result := TControl;
305+ end ;
306+
307+ function TControlsAccess.GetContainer : TControl;
308+ begin
309+ Result := TControl(inherited Container);
310+ end ;
311+
312+ function TControlsAccess.GetItem (AIndex: Integer): PPyObject;
313+ begin
314+ Result := Wrap(Container.Controls[AIndex]);
315+ end ;
316+
317+ function TControlsAccess.GetSize : Integer;
318+ begin
319+ Result := Container.ControlsCount;
320+ end ;
321+
322+ function TControlsAccess.IndexOf (AValue: PPyObject): Integer;
323+ var
324+ i : Integer;
325+ S : string;
326+ _obj : TPyObject;
327+ _value : TObject;
328+ _ctrl : TControl;
329+ begin
330+ Result := -1 ;
331+ with GetPythonEngine do begin
332+ if PyUnicode_Check(AValue) then begin
333+ S := PyUnicodeAsString(AValue);
334+ for i := 0 to Container.ControlsCount - 1 do
335+ if SameText(Container.Controls[i].Name , S) then begin
336+ Result := i;
337+ Break;
338+ end ;
339+ end else if IsDelphiObject(AValue) then begin
340+ _obj := PythonToDelphi(AValue);
341+ if _obj is TPyDelphiObject then begin
342+ _value := TPyDelphiObject(_obj).DelphiObject;
343+ if _value is TControl then begin
344+ _ctrl := TControl(_value);
345+ for i := 0 to Container.ControlsCount-1 do
346+ if Container.Controls[i] = _ctrl then begin
347+ Result := i;
348+ Break;
349+ end ;
350+ end ;
351+ end ;
352+ end ;
353+ end ;
354+ end ;
355+
356+ class function TControlsAccess.Name : string;
357+ begin
358+ Result := ' Controls' ;
359+ end ;
360+
361+ class function TControlsAccess.SupportsIndexOf : Boolean;
362+ begin
363+ Result := True;
364+ end ;
365+
262366initialization
263367 RegisteredUnits.Add(TControlsRegistration.Create);
264368
0 commit comments