[Gtk-sharp-list] Improving Gtk# The Wiki Page.

Enver ALTIN ealtin@parkyeri.com
Sun, 01 May 2005 06:37:50 +0300


--=-vsHq7qVCOoa+0mNHLfn+
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

Hey,

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
> this
> even one-word shorter:
>=20
>         ComboBox.Items[3]
>=20
> 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:

        type
                TSomeField=3Dclass(TCollectionItem)
                        // ...
                end;
       =20
                TSomeCollection=3Dclass(TCollection)
                private
                        function GetItem(Index: Integer): TSomeField;
                        procedure SetItem(Index: Integer);
                public
                        property Fields[Index: Integer]: TSomeField read Ge=
tItem write SetItem; default;
                end;

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

        Fields[n]

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:

        Fields.Remove(Fields[3]);
                      ^

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,
--=20
.O.
..O   Enver ALTIN                   |   http://skyblue.gen.tr/
OOO   Software developer @ Parkyeri | http://www.parkyeri.com/

--=-vsHq7qVCOoa+0mNHLfn+
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)

iD8DBQBCdE8OZCB2FZvqK0sRAkpTAJ9oJwJ3Kh5wXRARtXqa8NtoEZLaGQCghQK1
+i09bWtHdCPlIGo9o30aHO8=
=s2sj
-----END PGP SIGNATURE-----

--=-vsHq7qVCOoa+0mNHLfn+--