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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:31:06+00:00 2026-05-17T20:31:06+00:00

Question: i want to split two classes out to their own file, while avoiding

  • 0

Question: i want to split two classes out to their own file, while avoiding circular references.

i have a unit with some classes (and some enumerations and constants). Anyone will recognize Click and Clack the tappet brothers:

unit Cartalk;

interface

type
   TSolution = (solTransmission, solBrakes, solGremlins);

   TTappetBrother = class(TObject)
   public
      function GetSolution: TSolution; virtual; abstract;
   end;

   TClick = class(TTappetBrother)
   public      
      function GetSolution: TSolution; override;
   end;

   TClack = class(TTapperBrother)
   public
      function GetSolution: TSolution; override;
   end;

implementation

function TClick.GetSolution: TSolution;
begin
   Result := solTransmission;
end;

function TClack.GetSoltution: TSolution;
begin
   Result := solGremlins;
end;

end.

Now obviously my two classes TClick and TClick are quite complex. For manageability i’d like to split TClick and TClack out to their own units while not breaking any existing external code.

My first crack at it would be:

unit Cartalk;

interface

uses
   Cartalk_Click, Cartalk_Clack;

type
   TSolution = (solTransmission, solBrakes, solGremlins);

   TTappetBrother = class(TObject)
   public
      function GetSolution: TSolution; virtual; abstract;
   end;

   TClick = Cartalk_Click.TClick; //alias brought in from Cartalk_Click.pas

   TClack = Cartalk_Clack.TClack; //alias brought in from Cartalk_Clack.pas

 implementation

 end.

Perfect, i have all the same classes available in Cartalk.pas, now i just have to write Cartalk_Click.pas and Cartalk_Clack.pas:

unit Cartalk_Click;

interface

type
   TClick = class(TTappetBrother)
   public      
      function GetSolution: TSolution; override;
   end;

implementation

function TClick.GetSolution: TSolution;
begin
   Result := solTransmission;
end;

end.

Problem, of course, is that TTappetBrother and TSolution are not declared in this unit. So we add a reference to where they live to the uses, watch it fail, and reach the heart of my question:

unit Cartalk_Click;

interface

uses
   Cartalk;

type
   TClick = class(TTappetBrother)
   public      
      function GetSolution: TSolution; override;
   end;

implementation

function TClick.GetSolution: TSolution;
begin
   Result := solTransmission;
end;

end.

There is now a circular reference between Cartalk and Cartalk_Click.

Note: Of course i don’t have a Cartalk unit, with Click and Clack the tapper brothers – this is just an example. In reality i have 3 classes, 20 enumerations, and 293 constants in my unit.

  • 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-17T20:31:07+00:00Added an answer on May 17, 2026 at 8:31 pm

    Write a unit:

    unit Tappet;
    
    interface
    
    type
       TSolution = (solTransmission, solBrakes, solGremlins);
    
       TTappetBrother = class(TObject)
       public
          function GetSolution: TSolution; virtual; abstract;
       end;
    
    implementation
    
    end.
    

    and use it in the Click and the Clack units. Then write the CarTalk unit to use all three and export the needed types in its interface. No circular references needed.

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

Sidebar

Related Questions

I have a interesting question: I want to split the year into 4 quarters.
Say you have some list L and you want to split it into two
I have a little question I want to click on my smileys and insert
I have an R question--I want to make a vector of functions, and then
Well this is a simple question i want to filter two elements sorted reverse
This is related to an earlier question of mine. I want to have a
This question is a little odd, and I have spent a fair while pushing
I want to JOIN two table. Have no problem with that. I have problem
Question: I want to add a unique constraint on a mapping table (n:n). I
Question: I want code for: syntax highlighting (of programming languages) Language: C# or assembly

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.