Recent

Author Topic: How to inherit from a Generic class  (Read 23747 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11896
  • Debugger - SynEdit - and more
    • wiki
Re: How to inherit from a Generic class
« Reply #15 on: July 28, 2010, 11:19:36 pm »
No I havent tested any of this, but it may be worth a try.

Instead of inheritance try delegation

instead of (example with finale types)
  type TCircularQueueFoo = class(TQueueFoo);

do
  type TCircularQueueFoo = class(TObject);
    private
      theQueue: TQueueFoo


then of course, you need to have all the methods that TAbstractQueue implemented (at least public ones) and just forward (delegate) them to the "theQueue" object.

and (now I do not know if it works ...) for generics
Code: [Select]
type generic TQueue<A>= ....

type
  generic TCircularQueue<A>= class(TObject)
    private
      type
        TTheQueue = specialize TQueue<A>
      var
         FTheQueue: TTheQueue
       

Leledumbo

  • Hero Member
  • *****
  • Posts: 8833
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to inherit from a Generic class
« Reply #16 on: July 29, 2010, 05:34:40 am »
Hmm...looks like a solution :D

Amir61

  • New Member
  • *
  • Posts: 43
    • http://Amir.Aavani.net
Re: How to inherit from a Generic class
« Reply #17 on: July 31, 2010, 06:07:54 am »
But I have some function in my class (TAbstractQueue), how should I define them?

It is clear how to declare the Delete procedure or Size function in TAbstractQueue but I could not find a way to declare Insert function, for example?


 

TinyPortal © 2005-2018