* * *

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

Martin_fr

  • Hero Member
  • *****
  • Posts: 1120
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: 2715
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: 11
    • 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?


 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads