How to clone Controls?

Posted by Valeriy Bashkatov on 20-Oct-2017 06:41

Hello,

I have to create some controls similar to a control created as design time of the form in the Visual Designer in PDSOE.

For example,

I have label1 control on the form, and when form run I click on button to automaticaly create N copy of that control - label2, label3 ...

There is a method Controls:Clone (), but I did not understand how to work with it.

Any help would be much appreciated. Thanks!

Regards,
Valeriy

Posted by jquerijero on 23-Oct-2017 16:51

Controls:Clone will create a shallow copy of the Controls array, meaning you will get a new array object but each entry of the array will still point to the existing controls. Clone will not work for what you are looking for.

You can try something like this;

// See 1 below

DEFINE VARIABLE oDesignerControl  AS Infragistics.Win.Misc.UltraPanel  NO-UNDO.

// See 2 below

DEFINE INPUT PARAMETER oDesignerControl  AS System.Object   NO-UNDO.

Some LOOP Block:

  // 1. if type is known

  oDesignerControl = NEW Infragistics.Win.Misc.Ultralabel().  

  // 2. pass oDesignerControl control as System.Object and use DYNAMIC-NEW

  oDesignerControl = DYNAMIC-NEW oDesignerControl:GetType():ToString() (). // trying to remember this on top of my head if GetType() will return the derived class type name. If not use a string corresponding to the complete type name ( including namespace) of the control you are trying to create by just passing the type name as string to a method.

  // Add control to the form

  oDesignerControl:NAME = "<SomeName>" + STRING(i).

 ---- assign additional properties of oDesignerControl here like Text, Location and Size ----

 THIS-OBJECT:Controls:Add(oDesignerControl).

END.

All Replies

Posted by jquerijero on 23-Oct-2017 16:51

Controls:Clone will create a shallow copy of the Controls array, meaning you will get a new array object but each entry of the array will still point to the existing controls. Clone will not work for what you are looking for.

You can try something like this;

// See 1 below

DEFINE VARIABLE oDesignerControl  AS Infragistics.Win.Misc.UltraPanel  NO-UNDO.

// See 2 below

DEFINE INPUT PARAMETER oDesignerControl  AS System.Object   NO-UNDO.

Some LOOP Block:

  // 1. if type is known

  oDesignerControl = NEW Infragistics.Win.Misc.Ultralabel().  

  // 2. pass oDesignerControl control as System.Object and use DYNAMIC-NEW

  oDesignerControl = DYNAMIC-NEW oDesignerControl:GetType():ToString() (). // trying to remember this on top of my head if GetType() will return the derived class type name. If not use a string corresponding to the complete type name ( including namespace) of the control you are trying to create by just passing the type name as string to a method.

  // Add control to the form

  oDesignerControl:NAME = "<SomeName>" + STRING(i).

 ---- assign additional properties of oDesignerControl here like Text, Location and Size ----

 THIS-OBJECT:Controls:Add(oDesignerControl).

END.

Posted by Valeriy Bashkatov on 31-Oct-2017 05:38

Hi,

Thanks for your reply! It helped me to find a solution for my task.

Regards,

Valeriy

This thread is closed