Recent

Author Topic: fpc 3.2.2 - Forward a Class - how to ?  (Read 473 times)

paule32

  • Hero Member
  • *****
  • Posts: 647
  • One in all. But, not all in one.
fpc 3.2.2 - Forward a Class - how to ?
« on: June 06, 2025, 01:06:15 pm »
hello, how can I "forward" a class ?

given two classes:

type TBar = class;  // this give me: Error: forward declaration of
                            // class "TBar" must be resolved here

type TFoo = class(TBar)
       public
           procedure setAHandle(AHandle: Integer);
       end;

type TBar = class(TBaz)
       private
         AHandle: Integer;
       end;
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Awkward

  • Full Member
  • ***
  • Posts: 154
Re: fpc 3.2.2 - Forward a Class - how to ?
« Reply #1 on: June 06, 2025, 01:13:01 pm »
You must define forward class in same "type" block

paule32

  • Hero Member
  • *****
  • Posts: 647
  • One in all. But, not all in one.
Re: fpc 3.2.2 - Forward a Class - how to ?
« Reply #2 on: June 06, 2025, 01:21:27 pm »
following Code produce the Compiler Error:

Code: Pascal  [Select][+][-]
  1. type
  2.   TPersistent = class(TObject)
  3.   public
  4.     constructor Create;
  5.     destructor Destroy; override;
  6.    
  7.     class function ClassName: String; stdcall; virtual;
  8.   end;
  9.  
  10. type TComponent = class;
  11.   TControl = class(TComponent)
  12.   private
  13.     FAlign: TAlign;
  14.     FClientHeight: Integer;
  15.     FClientWidth: Integer;
  16.     FHeight: Integer;
  17.     FLeft: Integer;
  18.     FTop: Integer;
  19.     FWidth: Integer;
  20.   protected
  21.     function GetClientHeight: Integer;
  22.     function GetClientWidth: Integer;
  23.    
  24.     procedure SetClientHeight(AValue: Integer);
  25.     procedure SetClientWidth (AValue: Integer);
  26.    
  27.     procedure SetAlign(AValue: TAlign);
  28.   public
  29.     constructor Create(AOwner: TComponent);
  30.     destructor Destroy; override;
  31.    
  32.     class function ClassName: String; stdcall; virtual;
  33.   published
  34.     property Align: TAlign read FAlign write SetAlign default alNone;
  35.     property Height: Integer read FHeight write FHeight;
  36.     property Left: Integer read FLeft write FLeft;
  37.     property Top: Integer read FTop write FTop;
  38.     property Width: Integer read FWidth write FWidth;
  39.   end;
  40.  
  41.   TComponent = class(TPersistent)
  42.   private
  43.     FArray: array of TComponent;
  44.     FOwner: TComponent;
  45.     FIndex: Integer;
  46.     FTag: NativeInt;
  47.   protected
  48.     function  GetComponent(I: Integer): TComponent;
  49.     function  GetComponentCount: Integer;
  50.     function  GetComponentIndex: Integer;
  51.     function  GetComponentOwner: TComponent;
  52.    
  53.     procedure SetComponentIndex(AValue: Integer);
  54.     procedure SetComponentOwner(AOwner: TComponent);
  55.   public
  56.     constructor Create(AOwner: TComponent); virtual;
  57.     destructor Destroy; override;
  58.    
  59.     class function ClassName: String; stdcall; virtual;
  60.   published
  61.     property ComponentCount: Integer read GetComponentCount;
  62.     property ComponentIndex: Integer read GetComponentIndex write SetComponentIndex;
  63.     property Components[I: Integer]: TComponent read GetComponent;
  64.     property Owner: TComponent read FOwner;
  65.     property Tag: NativeInt read FTag write FTag default 0;
  66.   end;
  67.  
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Zvoni

  • Hero Member
  • *****
  • Posts: 3442
Re: fpc 3.2.2 - Forward a Class - how to ?
« Reply #3 on: June 06, 2025, 01:29:12 pm »
Quote
type TComponent = class;
  TControl = class(TComponent)
  private
    FAlign: TAlign;
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

paule32

  • Hero Member
  • *****
  • Posts: 647
  • One in all. But, not all in one.
Re: fpc 3.2.2 - Forward a Class - how to ?
« Reply #4 on: June 06, 2025, 05:07:31 pm »
ok, thank you.
it works like a charm.
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

 

TinyPortal © 2005-2018