Creating a new class from an existing one


I'm having a procedure that uses existing classes and create new ones form those. I'm trying to do this by this code:

  DestDoc := FManager.Replicate<TDocument>(SrcDoc);

  DestDoc.Id := 0;
  DestDoc.EntryDate := Now;
  ... (more changes, but removed for expamle purposes)


Is this a correct way to do it?

Make sure SrcDoc is not in the same manager. Then you should change properties before replicating. This is the "correct" example:

  SrcDoc := AnotherManager.Find<TDocument>(SomeId);
  SrcDoc.Id := 0;
  SrcDoc.EntryDate := Now;
  DestDoc := FManager.Replicate<TDocument>(SrcDoc);

Thank you, I will try.

Is possible to do it in the same manager?

Why do you want to do it in the same manager?

Because I already have one manager in the procedure :slight_smile:

It's just easier (less code changes), if not possible, then I will create a new one.

I'm converting an application to Aurelius and I'm stuck often, but I really like Aurelis and ever problem solved is asuch a pleasure when seeing parts of the application running smoothly :slight_smile:

Creating a new manager is a very lightweight operation and requires a few lines of code. It's really really simple.

Using the same manager is possible, but it's more complex, slower (due to needed copy operations) and requires more lines of code.

ok, thank you, I will try the solution you provided

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.