Ikke
2011-02-08 21:46:37 UTC
Hi everybody,
Just a quick question about generics and TLists. There are two classes,
TSomething and TOther, as follows:
TSomething = Class(TItem)
TOther = Class(TItem)
In another class, I hold a TList<TSomething> and a TList<TOther>. There
are many more lists, but for simplicity, I've only just used these two.
TSomething and TOther share some functionality (hence the TItem class),
but both are rather different, so I'd like to keep them in separate
lists.
However, when I want to display them in a number of grids (each in their
own grid), I wanted to pass these to a single procedure, defined as:
procedure FillGrid(sg : TStringGrid; items : TList<TItem>);
This gave me an error of 'incompatible types'. Does this mean I have to
manually fill a new TList<TItem>? Or is there another way?
I'm assuming here that (if a TSomething is a TItem) a TList<TSomething>
is a TList<TItem>, but that is apparently not the case...
Is there an easy solution for this problem, instead of having to write
different fill procedures for different classes?
Thanks in advance!
Ikke
Just a quick question about generics and TLists. There are two classes,
TSomething and TOther, as follows:
TSomething = Class(TItem)
TOther = Class(TItem)
In another class, I hold a TList<TSomething> and a TList<TOther>. There
are many more lists, but for simplicity, I've only just used these two.
TSomething and TOther share some functionality (hence the TItem class),
but both are rather different, so I'd like to keep them in separate
lists.
However, when I want to display them in a number of grids (each in their
own grid), I wanted to pass these to a single procedure, defined as:
procedure FillGrid(sg : TStringGrid; items : TList<TItem>);
This gave me an error of 'incompatible types'. Does this mean I have to
manually fill a new TList<TItem>? Or is there another way?
I'm assuming here that (if a TSomething is a TItem) a TList<TSomething>
is a TList<TItem>, but that is apparently not the case...
Is there an easy solution for this problem, instead of having to write
different fill procedures for different classes?
Thanks in advance!
Ikke