[gtkada] Where is the "Show" procedure?

Stephen Leake stephen_leake at acm.org
Sat May 29 13:56:54 CEST 2004


Wayne Lydecker <wayne at titan.com> writes:

> I am a newbie with gtk, but would like to develop applications with
> it.  I installed the latest version of gtkada (2.2.1), and built one
> of the examples, TTT_Test.
> 
> In an effort to understand it better, I removed the "use" clauses.

That is one way to do this, and it is instructive. But as you noticed,
it is hard. See below for a better way.

However, I'd like to take this opportunity to suggest that tutorials
not use 'use'. As this posting shows, it helps newbies to be able to
see where things come from.

> They were preventing me from finding where stuff is defined.  In
> the process, I had to modify a call to Show to be Tictactoe.Show.
> Problem is (for me, at least), Show is not defined in tictactoe.ads.
> How can this be?  That violates the rules of Ada as I know them,
> but I have had no Ada training beyond Ada 83.

Welcome to Ada 95. I suggest you go to www.adapower.com and look at
the list of books there, and go buy one (you'll probably have to get
it online, most bookstores don't stock Ada books anymore). 

Ada 95 supports inheritance. As an example, "Show" is defined in
gtk-widget.ads. Tictactoe declares:

   type Gtk_Tictactoe_Record is new Gtk.Box.Gtk_Vbox_Record with record
      Buttons : Gtk_Tictactoe_Buttons;
   end record;

So Gtk_Tictactoe_Record is derived from Gtk.Bin.Gtk_Vbox_Record. Which in
turn is declared in gtk-box.ads as:

   subtype Gtk_Vbox_Record is Gtk_Box_Record;

Also in gtk-box.ads there is:

   type Gtk_Box_Record is new Gtk.Container.Gtk_Container_Record with private;

in gtk-container.ads:

   type Gtk_Container_Record is new Gtk.Widget.Gtk_Widget_Record with private;

At each step of the derived type chain, all declared procedures are
inherited. So since Show is defined for Gtk_Widget_Record, it is also
defined for Gtk_Container_Record, Gtk_Box_Record, and finally Tictactoe.

Hmm. If you know C++, you understand this.


But back to your original problem; how to figure out where Show is
declared. The best way is to use the source navigation tools built
into your Ada IDE. Hmm. I'll assume you are using GNAT, but you didn't
say. The first step is to put the 'use' clauses back and compile the
program. This produces (among other things) *.ali files in the build
directory; these files contain cross reference information that the
IDE uses to find things. If you are using Emacs (the best IDE :), put
the cursor on Show in a file, hit C-c C-d, and you are magically
transported to the declaration of Show (that's how I found it above).
To trace the type declaration chain, place the cursor on the parent
type (Gtk_Vbox_Record for Gtk_Tictactoe_Record) and again hit C-c C-d.

In GPS (the _other_ IDE :), put the cursor on Show, and select Navigate
| Goto Declaration. You'll want to bind that to a key, possibly C-c
C-d :).

have fun,

-- 
-- Stephe




More information about the gtkada mailing list