On Thu, 14 Apr 2016, Ryan Joseph wrote:


On Apr 14, 2016, at 2:56 PM, Graeme Geldenhuys <mailingli...@geldenhuys.co.uk> 
wrote:

If you can give an actual example we can help. I've used TP then Delphi
and now Free Pascal for more than 20+ years. I can probably count on one
hand how many circular reference issues I had. So I dont' think it is
such a big problem as you make out.

Often moving uses clause references from the Interface section to the
Implementation section solve the problem. Sometimes using a base class
in the interface works. Sometimes using Interfaces (the language
feature) is a much better approach.

So again, if you can give an actual example of the various units, and
how they relate (use each other), then we might be able to help you further.

Regards,
 Graeme


I’ve just browsed over some code and found moving uses to the implementation 
did in fact help. That’s really helpful thank you both. However I’m still 
seeing some common patterns which just don’t seem Pascal friendly. I started 
using these more often after using Objective-C on Mac frequently and I really 
like it but it requires me to hack around the compiler in Pascal.

In that example below the “main” class has children it talks to using an 
interface and returning a reference to itself for introspection. They are 
interdependent but Pascal doesn’t offer a way to expose a global namespace for 
both the units as far as I know.  In other languages I would make another 
“globals” unit and keep forward references to TClassA, TClassB and IClassA.

==============================

ClassB.pas:

uses
 ClassA;  // <----- circular reference but I need to know about ClassA

type
 TClassB = class (IClassA)
   // when we implement this method we may need to know some things
   // about the parent (TClassA) so it must be included
   procedure ClassDidThis (parent: TClassA; action: integer);
 end;

ClassA.pas:

uses
 ClassB;

type
 TClassA = class
   child: TClassB;
 end;

You should not need TClassB here. You defeat the point of using an
interface.

  Child : IClassA;

should be sufficient.

Michael.
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to