SetOf is a solution for this particular case of wanting to have a general
purpose 'list' class that can be used for any kind of 'item' class. What
about a general solution that would be something like the C++ "template"
classes
TListTemplate<itemclass> = class
...defined just like a collection but use <itemclass> instead of TObject
then
Items : TListTemplate<myclassthatIwantacollectionof>
will expand out a definition of TListTemplate for that particular class.
I guess this looks like a macro which means preprocessing & more than one
pass to compile ... Mind you, macros wouldn't be so bad to have really
would they?
And while we're at it, another thing that would help would be 'inner
classes' like in Java, then you could achieve your customized TList using
var
Items : TList
private
function GetItem(index : integer) : TMyClass;
begin
result := TMyClass(inherited Items[index]);
end;
public
property Items[index : integer] : TMyClass read GetItem; default;
end;
And that would also let us have a proper subscribe/broadcast event system
MyButton.AddOnClickListener(TOnClickListener.Create
procedure onClick(Sender : TObject);
begin
< do stuff - can refer to the outer class form directly >
end;
end);
What are they putting in Delphi 6? Futuristic things like this or is it
just another set of bug fixes?
Mike
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Kurt
> Sent: Monday, 25 September 2000 10:12
> To: Multiple recipients of list delphi
> Subject: Re: [DUG]: Sorting a Collection
>
>
> Delphi's collection types and their inheritance structure can drive
> you crazy, however the problem Jeremy is having is caused by the fact
> that a "Collection" should not have an order : a collection with an
> "sort" property is a list. However the Delphi implementation is pretty
> darn bad: a TCollection uses a TList (for the sake of implementation),
> which gives this :
>
> TList = (collection with sort)
> TCollection = ((collection with sort), and hide the sort)
>
> And then a whole lot of other functionality is added to a TCollection,
> so that when you need a certain type of collection, a TCollection is the
> best choice.
>
> Neven MacEwan wrote:
> >
> > Paul
> >
> > Back to the start of this thread (sort of) does anyone elso out
> there think
> > Delphi (Object Pascal?)
> > could do with a SetOf base type (having just defined my nth
> collection type)
>
> I would like to see this:
> TCollection = (any old bunch of objects)
> TList = TCollection + Sort
> TSet = TCollection + (only one of each object)
> and then anyone can define as many subclasses as they want
> (eg: TTable = TCollection + (all objects have a unique key))
> without banging into a "half overlap" with what is provided by Delphi.
>
> >
> > ie
> >
> > Items: SetOf(TClass);
> >
> > which could implement
> >
> > Items.SortBy := TClass.Property;
> >
> [...]
> > with body of "unsubscribe delphi"
> ------------------------------------------------------------------
> ---------
> New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
> Website: http://www.delphi.org.nz
> To UnSub, send email to: [EMAIL PROTECTED]
> with body of "unsubscribe delphi"
---------------------------------------------------------------------------
New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
Website: http://www.delphi.org.nz
To UnSub, send email to: [EMAIL PROTECTED]
with body of "unsubscribe delphi"