user1769184
user1769184

Reputation: 1621

Solve unit cross reference issue

i create a first unit with basic class definitions like

unit_classtype;
type 
TMyClass = class(..)
     .....
end;

end.

In a second unit I store a lot of helper functions for this first unit

unit_classtype_helper; 

uses  unit_classtype;

    procedure WriteMyClasstoStringlist (aStringlist : TStringlist; aClass : TMyClass);


implementation

    procedure WriteMyClasstoStringlist (aStringlist : TStringlist; aClass : TMyClass);
begin
   aStringlist.add ('info on my Class', MyClass.Data );
   ....
end;

Now I want to build a MycLass.savetoFile function and use the code from WriteMyClasstoStringlist, but I can not include the helpunit in the class definition unit because of the cross reference.

Shifting the code is no option, I need some other solution

Upvotes: 0

Views: 350

Answers (1)

ain
ain

Reputation: 22749

I quess right now you're tring to include both units in the interface section, but you only need the unit_classtype_helper in the implementation of the unit_classtype so organise your code like this:

unit unit_classtype;

interface

type 
  TMyClass = class(..)
     .....
  end;

implementation

uses
  unit_classtype_helper;
...
end.

Upvotes: 3

Related Questions