[Gambas-user] How to duplicate Ctrls with preferences at runtime (2)

T Lee Davidson t.lee.davidson at gmail.com
Thu Mar 26 15:06:40 CET 2020


On 3/26/20 7:00 AM, ub2 at gmx.ch wrote:
> Dear Gambas Cracks
> 
> 2nd try, 1st see below
> (Was user at lists.gambas-basic.org partially down yesterday ?)
> 
> Best regards
> ub2
> 

I don't quite understand what you are trying to accomplish, and so I have not fully tested the following. But, perhaps something 
like this might be helpful for you:

' Gambas class file

Public MyChildren As New Object[]

Public Sub DuplicateChildren()

   For Each Child As Control In FMain.Children
     MyChildren.Add(CopyControl(Child))
   Next

End

Public Sub CopyControl(Child As Control) As Control

   Dim ChildClass As Class
   Dim ChildCopy As Object

   ChildClass = Object.Class(Child)
   ChildCopy = Object.New(ChildClass.Name, [FMain])
   For Each Symbol As String In ChildClass.Symbols
     If ChildClass[Symbol].Kind = Class.Property Then
       ' Some symbols are created read-only. Simply ignore them with TRY
       Try Object.SetProperty(ChildCopy, Symbol, Object.GetProperty(Child, Symbol))
     Endif
   Next

   Return ChildCopy

End


-- 
Lee


More information about the User mailing list