[gtkada] GObject properties

Arnaud Charlet charlet at ACT-Europe.FR
Wed Sep 24 15:19:38 CEST 2003


> Partly, yes. So for example with Use_Markup_Property there is no problem.
> But with Mnemonic_Keyval_Property it seems I still need to use
> Glib.Properties.Uint_Properties.Set_Property which the spec says can
> be ignored.

I believe you missed the most important part of the spec:

--  Two functions are provided for each type of property: Set_Property and
--  Get_Property, which allow easy modification of specific widget
--  properties. For instance, you could do the following:
--      declare
--          Button : Gtk_Button;
--      begin
--          Gtk_New (Button, "old label");
--          Set_Property (Button, Label_Property, "new label");
--      end;
--  to modify the label of a button.
--
--  Likewise, you can retrieve the current label with:
--      Current : String := Get_Property (Button, Label_Property);
--
--  Dispatching is used ensure type-safety while using properties. The
--  appropriate Set_Property/Get_Property functions are called depending
--  on the type of the property you are trying to use. This is checked
--  statically by the compiler, which provides additional type-safety
--  compared to the C library.
--
--  Note that some properties are read-only, and thus do not have the
--  Set_Property subprogram defined.

So in short, use the documented Glib.Properties.Set/Get_Property and stay away
from the internal packages.

Incidentally, this is a good example of a bad side effect of abslutely
avoiding 'use' clauses: by doing so, you put yourself into a situation
where you absolutely need to know where the function has been declared,
which can be very error prone when the function is inherited implicitely,
as is the case here, and as is the case for most tagged primitive operations.

So my advice would be to use 'use' clauses in such cases, e.g:

with Glib.Properties; use Glib.Properties;
[...]
Get_Property (Label, Mnemonic_Keyval_Property);

If you really want to avoid 'use' clauses, then the proper notation would be:

with Glib.Properties;
[...]
Glib.Properties.Get_Property (Label, Mnemonic_Keyval_Property);

This is actually a good example for people that assume that use clauses are
always more readable and that there is never a good reason for not using
them: this is not the case here, since Glib.Properties does
not contain explicitely this Get_Property function, however this is
clearly the right notation, since Property_Uint_RO *is* defined in
Glib.Properties.

Arno



More information about the gtkada mailing list