comp.lang.ada
 help / color / mirror / Atom feed
From: "Bobby D. Bryant" <bdbryant@mail.utexas.edu>
Subject: Generic package vs GTK callbacks.
Date: 2000/01/31
Date: 2000-01-31T10:00:32+00:00	[thread overview]
Message-ID: <38955D00.FBBBA05D@mail.utexas.edu> (raw)

I have a generic package that I want to instantiate at some arbitrary
depth in my code, so I can prompt for some user values before I
instantiate it.  (I can do this OK by instantiating it in the
declaration part of some appropriate procedure that is called after the
prompting, and which obtains the values previously stored in variables
visible to that procedure, but I notice that AAA2ndL says that
instantiating within a procedure declaration is "very rare", so if I'm
going about this part wrongheadedly let me know -- it might obviate the
question I'm asking below.)

The problem arises because after instantiation I want to "talk to" the
instantiated with GTK callbacks.  I.e., I want to instantiate it and
then let button clicks invoke its procedures, or at least let the button
clicks invoke other procedures that invoke procedures in the generic
package in turn.

However, if I declare the callback functions within the declaration part
of the procedure that instantiates the package, GNAT complains with the
familiar "subprogram must not be deeper than access type".  Ditto if I
try to use procedures local to the package for the callbacks[1].  But if
I declare the callback functions elsewhere, they cannot see the
instantiation at all.

[1] The above is slightly simplified w.r.t. the actual problem: I am
actually trying to "talk to" the generic child of a generic package.
The description above is factual except that my "try to use procedures
local to the package" actually refers to procedures local to the *child*
package, which is instantiated at the same place the parent is.  (Or
better yet, I would like to have callback procedures that instantiate a
new child of the previously instantiated parent.)

Here's a schematic of what I'm up to (the actual code is *much* too
large to post):

---8<-------

-- The main program calls whatever.do_cool_stuff_with_map.

with
    map, -- The generic package.
    map.child; -- The generic child package.
package body whatever is
    -- XXX
    procedure do_cool_stuff_with_map is
        package this_map is
            new map( x => 100, y => 80 )
        package this_map_child is
            new this_map.child( foo => foo_type'last ); -- i.e., "bar".
        -- YYY
    begin
        -- This procedure is called after the instantiation values
(shown as constants
        -- above) have been loaded by other parts of the program.  No
problems there.
        -- Now I want to set up some GTK callbacks.  By preference a
callback would
        -- create another "new this_map.child()", but I could probably
make an ugly
        -- workaround if I could get a callback to connect to a
procedure in the child
        -- package at all.  No luck either way.  If I try to do it at
XXX, then this_map
        -- is not visible.  If I try to do it at YYY, then I get the
"deeper than access type"
        -- problem.
        -- Notice that I don't have to leave the current procedure to
finish the
        -- program, except in the sense that the callbacks always
"leave" the local
        -- flow of control.
    end do_cool_stuff_with_map;
begin
    -- Nothing important has to happen here.
end whatever;

--- 8<-------

Is there a trick for working around this kind of problem?

Thanks,

Bobby Bryant
Austin, Texas





             reply	other threads:[~2000-01-31  0:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-01-31  0:00 Bobby D. Bryant [this message]
2000-02-01  0:00 ` Generic package vs GTK callbacks Stephen Leake
2000-02-01  0:00   ` Bobby D. Bryant
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox