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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:03:58+00:00 2026-05-15T16:03:58+00:00

Is there any work-around to create mutual referencing records in Delphi? Here’s the simplified

  • 0

Is there any work-around to create mutual referencing records in Delphi? Here’s the simplified version of the code:

MyRec1 = record
  arr: MyRec2Array;
end;

MyRec2 = record
  mr: MyRec1;
end;

MyRec2Array = array of MyRec2;

Apparently forward declaration of record types

MyRec2 = record;

doesn’t work in Delphi for Win32.

Switching to classes instead of records is not good, because this will increase memory consumption and code complexity, so I’d rather stay with records.

Any suggestions?

  • 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-15T16:03:59+00:00Added an answer on May 15, 2026 at 4:03 pm

    Records are value types, not reference types. That means that all records used as members of a larger data structure are placed inline in the structure itself instead of as a pointer. Trying to create two records which contain each other would throw the compiler into an infinite loop while it tries to figure out the structure of the records. That’s probably the reason why you can’t forward-declare a record, and even though you’re trying to insert a reference type (dynamic array) here, you still can’t violate the language rules.

    But what you can do is declare a pointer-to-record type as a forward declaration, like so:

    PMyRec2 = ^MyRec2
    ...
    MyRec2 = record
      ...
    end;
    

    Of course, once you start using pointers to records, you have to worry about allocating and freeing the memory, and the code complexity you were trying to avoid by not using classes appears in your project. Bottom line: do this with classes. Make one of the records, if not both of them, a class. It’s the simplest way, really.

    And the extra memory overhead is negligible. It comes out to a pointer to the object for each reference, which you’d need for pointers to objects anyway, plus one hidden field (4 bytes) per instance before D2009 or two of them (8 bytes) on D2009 or later. That’s not very much at all.

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

Sidebar

Related Questions

Is there any work being done to create a C# compiler to produce native
Is there any chance to get this work? I want my tests to be
Is there any reason something like this would not work? This is the logic
Are there any jQuery 1.3 animation-transitions that work in both Firefox 3 and IE7?
Is there any reason why JQuery would not work when used in an ASPX
Is there any way to make PVRTC textures work on the iPhone Simulator?
Is there any reason why this shouldn't work? [PseudoCode] main() { for (int i
Are there any O/R mappers out there that will automatically create or modify the
Is there any workaround for the following 1 pixel to the left bug? <!DOCTYPE
Is there any workaround to allow actionscript3 write to file system without adobe air?

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.