[Gtk-sharp-list] Improving Gtk# The Wiki Page.
Sun, 01 May 2005 06:37:50 +0300
On Sun, 2005-05-01 at 05:40 +0300, Enver ALTIN wrote:
> There's something called the default index property (denoted
> with /default/ keyword while defining it) in Delphi/OOP which makes
> even one-word shorter:
> makes the use of Items collection just as easy as an array, by mapping
> the index (3 in this case) to the get method of the default indexer
> property. I'm totally unsure how this could be adopted for Collection
> classes though.
Explaining this further, here's how it works:
function GetItem(Index: Integer): TSomeField;
procedure SetItem(Index: Integer);
property Fields[Index: Integer]: TSomeField read Ge=
tItem write SetItem; default;
Sorry for the Pascal-ism. I was in love with it because of the tightly
integrated IDE, but now I think at least half of this stuff is just
bullshit. That said, if you had an instance of TSomeCollection, say,
"Fields", you'd access nth item by just doing
that's all. This would simply call GetItem() with "n" and return its
value. Of course, there are limitations. Fields property can only have
one indexer, and its name _has to be_ *Index*. Apparently, GetItem() and
SetItem() functions have to accept one single parameter, named Index.
Conceptually it makes a TCollection very usable and nice.
Just if you haven't noticed, there is a very nice trick here.
TCollection has some methods like Add() and Remove(), which creates+adds
a TSomeField and returns it back and removes an item from the
collection. Folks at Borland did a good thing by *not* embedding this
default-indexer-property feature directly into the base Collection
class, but made it optional to the derived class. This way, using the
Delphi IDE, for example, if you want to remove an item by its index
you'd do something like:
Press Ctrl+Space right after "Remove(" and let the IDE autocompletion
bring you possible choices _only_ of TSomeField type. The other way
around, you'd have almost any TCollectionItem-descendant instance in the
autocompletion box. A total mess, I'd say.
Please excuse me if I'm wasting your time with even more irrelevant
stuff that you probably already know.
Thanks for your patience,
..O Enver ALTIN | http://skyblue.gen.tr/
OOO Software developer @ Parkyeri | http://www.parkyeri.com/
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
-----END PGP SIGNATURE-----