Forward Class in different Units lazarus / 21-General ---------------------------------------------------------------------- Weitentaaal · 2023-02-22 09:17 Hello, is it Possible to Split this unit up into two parts, where each holds a Class. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i MyClass1 = Class; MyClass2 = class;private   class1: TMyClass1;end; MyClass1 = classprivate   class2: TMyClass2;end;  curretnly i have both classes (MyClass1, MyClass2) in the same unit. i want to seperate them into two different units. Is that possible ? thanks in advance ---------------------------------------------------------------------- marcov · 2023-02-22 09:32 No. ---------------------------------------------------------------------- Weitentaaal · 2023-02-22 09:58 ok thanks ---------------------------------------------------------------------- howardpc · 2023-02-22 18:59 I agree with Marco. However, if you slightly redesign your classes using a base class, and jump through a few hoops you can achieve a close-coupled TClass1 and TClass2 in different units. Here are the two example units: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit uClass1andBase; {$mode ObjFPC}{$H+} interface uses  Classes; type   TBaseClass = class(TObject)  protected    FClass1: TBaseClass;    FClass2: TBaseClass;  public    procedure ShowFClassType;    destructor Destroy; override;  end;   TClass1 = class(TBaseClass)  public    constructor Create;  end; var  FInitialised1: Boolean=False;  FInitialised2: Boolean=False; implementation uses  uClass2; { TBaseClass } destructor TBaseClass.Destroy;begin  FClass1.Free;  FClass2.Free;  inherited Destroy;end; procedure TBaseClass.ShowFClassType;begin  WriteLn('This class is type ', ClassName);  case Assigned(FClass2) of    True:  WriteLn('FClass2 is type ', FClass2.ClassName);    False: WriteLn('FClass2 is Nil');  end;  case Assigned(FClass1) of    True:  WriteLn('FClass1 is type ', FClass1.ClassName);    False: WriteLn('FClass1 is Nil');  end;end; { TClass1 } constructor TClass1.Create;begin  FInitialised1 := True;  FClass1 := Nil;   if not FInitialised2 then begin    FClass2 := TClass2.Create;    FInitialised1 := False;  end;end; end. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit uClass2; {$mode ObjFPC}{$H+} interface uses  Classes, uClass1andBase; type   TClass2 = class(TBaseClass)  public    constructor Create;  end; implementation { TClass2 } constructor TClass2.Create;begin  FClass2 := Nil;  FInitialised2 := True;   if not FInitialised1 then begin    FClass1 := TClass1.Create;    FInitialised1 := True;  end;end; end. Here is the program needed to exercise the two units: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program CoupledClasses; {$IFDEF MSWINDOWS} {$AppType  console}  {$ENDIF} uses  uClass1andBase, uClass2; var  c1: TClass1;  c2: TClass2; begin  c1 := TClass1.Create;  c1.ShowFClassType;   WriteLn;   c2:= TClass2.Create;  c2.ShowFClassType;   WriteLn('Press Enter to exit');  ReadLn;   c1.Free;  c2.Free;end.