Cloning an Object - Forum - OpenEdge Development - Progress Community
 Forum

Cloning an Object

This question is not answered

Hi

I have a requirement to copy an object at runtime. The object in question is a RadGridView (or more specifically an object inheriting RadGridView).

I know that cloning objects wasn't directly or easily achievable in the past, but I was wondering if the new reflection functionality would now make this possible.

Before I start experimenting, has anyone else had any experience/success in trying this? Or is there a better way to go about copying an object?

Thanks for any help.

Dave

All Replies
  • You'd have to use .NET reflection for the .NET part and ABL reflection for the ABL part.

    A hell of a job for a complex component with child objects ....



    Von: David Williams <bounce-davidwilliamswinterfloodcom@community.progress.com>
    Gesendet: 03.05.2017 11:45 vorm.
    An: TU.OE.Development@community.progress.com
    Betreff: [Technical Users - OE Development] Cloning an Object

    Update from Progress Community
    David Williams

    Hi

    I have a requirement to copy an object at runtime. The object in question is a RadGridView (or more specifically an object inheriting RadGridView).

    I know that cloning objects wasn't directly or easily achievable in the past, but I was wondering if the new reflection functionality would now make this possible.

    Before I start experimenting, has anyone else had any experience/success in trying this? Or is there a better way to go about copying an object?

    Thanks for any help.

    Dave

    View online

     

    You received this notification because you subscribed to the forum.  To stop receiving updates from only this thread, go here.

    Flag this post as spam/abuse.

    Architect of the SmartComponent Library and WinKit

    Consultingwerk Ltd.

  • Thanks, Mike.

    You've confirmed my initial thoughts.

  • Well, you could also serialize the object and deserialize into a new instance.

    Or you could implement/override a Clone() method in the class.

    -.NET objects aren't guaranteed to have a Clone method, the ones that do and follow .NET best practices will also implement the IClonable interface.

    - ABL objects will inherit one from Progress.Lang.Object, but you'll need to override it to add an actual implementation

  • Object serialization only works on objects that are marked as serializable.  If just one object in that tree isn't, then it won't serialize properly.

    Same with clonable objects.  You'd have to check the whole object tree for the RadGridView and all the objects it uses to make sure they are all clonable/serializable.  

    This isn't a simple task to clone the whole object tree.

    Better, is to move your object definition into something that is more appropriate to making multiple copies, such as an external file definition like JSON or XML, or to use a factory object with a generator that can configure multiple objects with the same setup.