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 223987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:16:27+00:00 2026-05-11T19:16:27+00:00

I have a record that contains a dynamic array. It is normal that when

  • 0

I have a record that contains a dynamic array. It is normal that when you assign one array variable to another, in fact only the pointer to that array is assigned. This means that when you do that, both the variables point to the same array until you change the size of one of them. Therefore, when I want to assign a separate copy of an array to a variable, I use the Copy() function.

In this case, however, my array is a field of a record:

  TMyRec = record
    Value: integer;
    &Array: array of integer;
  end;

When I declare two variables of type TMyRec and then assign one to another, the “Array” fields in both of the records will be pointing to the same address in memory.

To solve that sort of problem I decided to overload the assign operator as follows:

TMyRec = record
  Value: integer;
  &Array: array of integer;
public
  class operator Implicit(Value: TMyRec): TMyRec;
end;

class operator TMyRec.Implicit(Value: TMyRec): TMyRec;
begin
  Result := Value;
  Result.&Array := Copy(Value.&Array);
end;

If this worked, I wouldn’t have to copy all array fields in my records separately after assigning TMyRecord variables one to another.

Here is what I do:

var
  Rec1, Rec2: TMyRec;
begin
  Rec1.Value := 10;
  SetLength(Rec1.Array, 1);

  //I expected the "Implicit" method to be invoked here (but it is not...)
  Rec2 := Rec1;

  //if I do that, the Rec1.Array[0] will also be changed to 1 - I don't want that to happen
  Rec2.Array[0] := 1;
end;

Is there a way to make my operator overload work as I want it to? The thing is that I’m trying to overload the default assignment operator. Isn’t that possible?

  • 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-11T19:16:27+00:00Added an answer on May 11, 2026 at 7:16 pm

    You could put your array inside an object instance which implements an interface, and store a reference to that interface inside the record. That way, when you try to assign to the array via the interface (and thus via the object), it can check its reference count and help with copy-on-write semantics.

    Alternatively, you could use type-unsafe tricks to find out the reference count of the array, and manually copy before write if multiple references exist; but that would be unsupported and would break if the dynamic array implementation changed.

    I wrote up how to implement a copy-on-write array structure wrapped up in a record. It’s implemented as a generic type, but nothing stops you from using a concrete array type instead, it just won’t be as general.

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

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You didn't specify whether you're using C# or VB, but… May 12, 2026 at 12:24 am
  • Editorial Team
    Editorial Team added an answer Firstly, use operator!=() on iterators, not operator<(): while (it !=… May 12, 2026 at 12:24 am
  • Editorial Team
    Editorial Team added an answer Mesh is a syncronisation platform which can be used to… May 12, 2026 at 12:24 am

Related Questions

I've got an in-memory dataset with several fields, one of which is a primary
How do I attach an onclick event to a link_to_function such that clicking on
I have a collection of records in my database that I want to print
I'm using Delphi 2007 Pro. I have a runtime package that includes a number

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.