[gtkada] Passing context objects to handlers via Register_Handler

R. Tyler Croy tyler at monkeypox.org
Thu Jan 12 00:56:36 CET 2017


(replies inline)

On Mon, 09 Jan 2017, Nicolas Setton wrote:

> On 09/01/2017 12:41, R. Tyler Croy wrote:
> >Before I do something gnarly and add some globals to my application, I'm
> >curious to learn more about patterns for sharing context with registered
> >handlers.
> >
> >The problem I have is that there is shared state which I have in the Main
> >procedure which I would like to make use of during the handler procedures. My
> >first attempt was create a new Gtkada_Builder_Record type with a record
> >extension, but that failed miserably.
> >
> >Outside of adding a global which I grab across package boundaries, it's not
> >clear to me how to pass 'context' here :(
> >
> >
> >Any suggestions or pointers would be most helpful!
> 
> Your first idea, to extend Gtkada_Builder_Record, looks like the right thing
> to do - what didn't work?

I *believe* that this isn't working as I would like because
Gtkada_Builder_Record isn't a tagged type. From my understanding,
procedure/function signatures using Gtkada_Builder_Record'Class would gladly
accept my extended (and tagged) record, if the "parent" were to be tagged.

For reference, here's what Gtkada_Builder_Record looks like:

   type Gtkada_Builder_Record is new
     Gtk.Builder.Gtk_Builder_Record with private;
   type Gtkada_Builder is access all Gtkada_Builder_Record'Class;

Here's a sample snippet of what I tried (from arun.adb):

      type Arun_Builder_Record is new Gtkada_Builder_Record with record
         Extended : Boolean;
      end record;
      type Arun_Builder is access all Arun_Builder_Record'Class;

      Builder     : Arun_Builder;
      -- snip
   begin

      Gtk.Main.Init;
      Gtk_New (Builder);
      -- sinp


This results in the predictable error of:

    arun.adb:56:16: expected type "Gtkada_Builder" defined at gtkada-builder.ads:84
    arun.adb:56:16: found type "Arun_Builder" defined at line 40
    gprbuild: *** compilation phase failed


I'm still a relative novice at object-oriented programming with Ada 2012, so I
might not be extending things correctly here. Happy to try whatever alternative
approaches you might recommend here.



Cheers
- R. Tyler Croy

------------------------------------------------------
     Code: <https://github.com/rtyler>
  Chatter: <https://twitter.com/agentdero>
     xmpp: rtyler at jabber.org

  % gpg --keyserver keys.gnupg.net --recv-key 1426C7DC3F51E16F
------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: </pipermail/gtkada/attachments/20170111/704d0427/attachment.sig>


More information about the gtkada mailing list