Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6960317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:23:13+00:00 2026-05-27T15:23:13+00:00

Delphi has a standard mechanism where one object can be copied from another, paraphrased

  • 0

Delphi has a standard mechanism where one object can be copied from another, paraphrased here as:

class Persistent 
{
    protected AssignError(Persistent source)
    {
       throw new ConvertError("Cannot assign a {0} to a {1}", source.GetType().Name, this.GetType().Name);
    }

    protected virtual AssignTo(Persistent destination)
    {
        destination.AssignError(this);
    }

    public virtual Assign(Persistent source)
    {
       source.AssignTo(this);
    }
}

Does the .NET FCL has a canonical syntax of copying objects between each other?

e.g.:

interface IPersistent
{
   public virtual Assign(Object source);
}

public class User : IPersistent
{
    private Image avatarThumbnail;
    private String name;

    public override Assign(Object source)
    {
       if (source is User)
       {
          this.avatarThumbnail = source.avatarThumbnail;
          this.name = source.Name;
       }
       else if (source is Image)
           avatarThumbnail = (Image)source;
       else if (source is DirectoryEntry)
           name = ((DirectoryEntry) source).Firstname + " " + ((DirectoryEntry) source).Lastname;
       else
           throw new AssignError("Assign from {0}", source.GetType());
    }
}

Yes i just invented a standard IPersistent interface; but is there already a mechanism to copy objects between each other?

Update

Note: i am talking about the opposite of cloning an object.

User originalUser = new User();
User theClone = originalUser.Clone();
theClone.Lastname = "Guyer";

originalUser.Assign(theClone);

Or, i don’t even need to have a clone at all:

User u = new User();
u.Assign(salesOrder); //copy name/e-mail from the sales order

or

SalesOrder s = new SalesOrder();
s.SalesOrderDate = DateTime.Now;
User customer = new Customer("Kirsten");
s.Assign(user); //copy sold-to/ship-to information from the user
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:23:14+00:00Added an answer on May 27, 2026 at 3:23 pm

    The .NET framework has the ICloneable interface:

    Supports cloning, which creates a new instance of a class with the same value as an existing instance.

    And:

    The ICloneable interface contains one member, Clone, which is intended to support cloning beyond that supplied by MemberwiseClone. For more information about cloning, deep versus shallow copies, and examples, see the Object.MemberwiseClone method.


    Update:

    As far as I know, there is nothing equivalent to what you want (standard way to copy some values between different objects) in the BCL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Delphi has a $WARN compiler directive that allows one to selectively enable or disable
Is there any class in the .NET framework that can read/write standard .ini files:
Delphi 2010 has a nice set of new file access functions in IOUtils.pas (I
I have a Delphi application that has a document browser as the main form.
I am using Delphi 2009 which has the FastMM4 memory manager built into it.
I'm writing a tcp client in Delphi for a server that has a series
When I compile our project use Delphi 2010 Trial, there has a fatal error
Are there any CI-Systems for Delphi like Hudson for Java? Does Hudson has any
I use Delphi 7 and import from a WDL file to create a SOAP
I am a little confused why Delphi has Debug information in linking and debug

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.