comp.lang.ada
 help / color / mirror / Atom feed
* Generic package vs GTK callbacks.
@ 2000-01-31  0:00 Bobby D. Bryant
  2000-02-01  0:00 ` Stephen Leake
  0 siblings, 1 reply; 3+ messages in thread
From: Bobby D. Bryant @ 2000-01-31  0:00 UTC (permalink / 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





^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Generic package vs GTK callbacks.
  2000-01-31  0:00 Generic package vs GTK callbacks Bobby D. Bryant
@ 2000-02-01  0:00 ` Stephen Leake
  2000-02-01  0:00   ` Bobby D. Bryant
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Leake @ 2000-02-01  0:00 UTC (permalink / raw)


"Bobby D. Bryant" <bdbryant@mail.utexas.edu> writes:

> 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.  <snip>
> 
> The problem arises because after instantiation I want to "talk to" the
> instantiated with GTK callbacks. <snip>
> 
> 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". 
> <snip>

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

Unfortunately, you can't use 'Unchecked_Access for subprograms (RM
13.10 (5)). However, if you are using GNAT, you can try
'Unrestricted_Access. As the GNAT Reference Manual says, "this is a
user-beware attribute"; you can get dangling references and other
problems. From your description, I think you would be ok. Make sure
you put in comments that "prove" you won't get dangling references;
you need to understand when Gtk saves pointers, and when it frees them
(usually when the associated object is "destroyed"). Good luck - I've
just started using Gtk, and find it very confusing on this point.

For a totally different approach, if you are on Win32, try using my
Windex system (http://users.erols.com/leakstan/Stephe/Ada/windex.html)
instead of Gtk. Windex takes a totally different approach to handling
windows events; instead of requiring library-level "callbacks", you
can define a local tagged window type and override the window event
handler functions. I haven't needed to do this yet, but you can.

Windex is _not_ as powerful as Gtk (yet), but this is one situation
where it appears to be better :).

-- Stephe




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Generic package vs GTK callbacks.
  2000-02-01  0:00 ` Stephen Leake
@ 2000-02-01  0:00   ` Bobby D. Bryant
  0 siblings, 0 replies; 3+ messages in thread
From: Bobby D. Bryant @ 2000-02-01  0:00 UTC (permalink / raw)
  To: Stephen Leake

Stephen Leake wrote:

> Unfortunately, you can't use 'Unchecked_Access for subprograms (RM
> 13.10 (5)). However, if you are using GNAT, you can try
> 'Unrestricted_Access.

Thanks.  I'll look in to that.


>  Good luck - I've
> just started using Gtk, and find it very confusing on this point.

I used it for several experiments last year, but I'm just now starting to use
it for non-trivial work.  I'm "over the hump" in some regards, but expect
that I'll still have to learn much the hard way.

Bobby Bryant
Austin, Texas






^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-02-01  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-01-31  0:00 Generic package vs GTK callbacks Bobby D. Bryant
2000-02-01  0:00 ` Stephen Leake
2000-02-01  0:00   ` Bobby D. Bryant

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