Generic inheritance lazarus / 13-General ---------------------------------------------------------------------- YarUnderoaker · 2010-10-07 05:52 There some generic classes Code: [Select]  generic GOrderedList = class(TObject)   private     type       TOrderedList = specialize GList;     var       FList: TOrderedList;   protected     procedure PushItem(AItem: T); virtual; abstract;     function PopItem: T; virtual;     function PeekItem: T; virtual;     property List: TOrderedList read FList;   public     constructor Create; virtual;     destructor Destroy; override;     function Count: Integer;     function AtLeast(ACount: Integer): Boolean;     function Push(const AItem: T): T;     function Pop: T;     function Peek: T;   end;   // GStack   //   generic  GStack = class(GOrderedList)   protected     procedure PushItem(AItem: T); override;   end;GStack can't be inheritor of GOrderedList, unlike Delphi, and on fly specialize won't work too. How this can be solved? ---------------------------------------------------------------------- Leledumbo · 2010-10-07 06:36 Try: Code: [Select]generic GStack = class(specialize GOrderedList) protected   procedure PushItem(AItem: T); override; end; ---------------------------------------------------------------------- YarUnderoaker · 2010-10-07 06:49 I say, the specialization on the fly is not working  GStack = class(specialize GOrderedList) -> Error: Identifier not found "T" Error: Type identifier expected Error: Generics without specialization cannot be used as a type for a variable Fatal: Syntax error, "=" expected but "<" found ---------------------------------------------------------------------- Leledumbo · 2010-10-07 09:21 What FPC version are you using? The trunk (2.5.1) version should work ---------------------------------------------------------------------- YarUnderoaker · 2010-10-07 10:13 FPC 2.4.3 I have now switched to 2.5.1 and try to. ---------------------------------------------------------------------- YarUnderoaker · 2010-10-07 10:28 I switch to 2.5.1 and clear&build Lazarus. Same error (Lazarus-0.9.29-27578-fpc-2.5.1-20101005-win32) ---------------------------------------------------------------------- Leledumbo · 2010-10-07 11:11 Whoops, sorry. It should be for specialized generic class. Right now, AFAIK, it's not possible to do that. The only thing I can imagine is by using delegation (i.e. having the parent class as child class' attribute). ---------------------------------------------------------------------- YarUnderoaker · 2010-10-07 11:26 Quote from: Leledumbo on October 07, 2010, 01:11:25 pmparent class as child class' attribute.In this case, it reduces the sense of generics to zero ---------------------------------------------------------------------- Chronos · 2010-10-07 15:48 Question is, if developers have desire to implement full generics support at least as Delphi have. How much money could implementation cost. It would be better to give money to FPC developers than pay every year for licence for new versions of Delphi. Now we have problem if we want to use Lazarus/FPC for professional software as it is still mainly enthusiastic project. ---------------------------------------------------------------------- YarUnderoaker · 2010-10-07 20:31 Quote from: chronos on October 07, 2010, 05:48:32 pmQuestion is, if developers have desire to implement full generics support at least as Delphi have. How much money could implementation cost. It would be better to give money to FPC developers than pay every year for licence for new versions of Delphi. Now we have problem if we want to use Lazarus/FPC for professional software as it is still mainly enthusiastic project. GLScene developers have same problem  but enthusias and progress must not stop because if everything is done for money - the human species comes to the decline  PS: sorry for offtopic ---------------------------------------------------------------------- Leledumbo · 2010-10-08 01:09 QuoteNow we have problem if we want to use Lazarus/FPC for professional software as it is still mainly enthusiastic project. Nah, not really. I've been using it for some professional projects. Not all professional projects require full generics support, right? ---------------------------------------------------------------------- Chronos · 2010-10-08 03:46 Hoho, you are trying to tell us that we can use generics using templates for professional application long ago. http://www.dummzeuch.de/delphi/object_pascal_templates/english.html So conclusion would be that we don't need native implementation at all. In usage of generics all matters. Inheritance is core feature as it is widely used across generic class definition like TList and TStream. Example FGL unit implementation of TFPGList use shared standard class TFPSList as non generic ancestor as workaround for lack of generics inheritance. It works but it is not clear abstract and scalable solution. And that is real problem for any developer who tries to build clear generics library similar to Delphi Generics.Collections. In commercial project question is when company plans and will implement feature? In open source project question is when volunteers will implement feature. And who are they? Core developers or anybody who are willing help. ---------------------------------------------------------------------- felipemdc · 2010-10-08 04:31 Quote from: chronos on October 07, 2010, 05:48:32 pmQuestion is, if developers have desire to implement full generics support at least as Delphi have. How much money could implementation cost. It would be better to give money to FPC developers than pay every year for licence for new versions of Delphi. Now we have problem if we want to use Lazarus/FPC for professional software as it is still mainly enthusiastic project. You should ask this in the Free Pascal mailling list. Maybe one of the fpc developers is interrested. If no FPC developers are interrested, then you can contact me, and I'll check with a co-worker if he is interrested in the bounty. It might also be interresting to know that this company offers commercial support for Lazarus / FPC: http://www.lazarussupport.com/