comp.lang.ada
 help / color / mirror / Atom feed
From: jsa@alexandria (Jon S Anthony)
Subject: Re: Ada/Motif problem...
Date: 1996/08/28
Date: 1996-08-28T00:00:00+00:00	[thread overview]
Message-ID: <JSA.96Aug28183136@alexandria> (raw)
In-Reply-To: 4vupg6$ljf@goanna.cs.rmit.edu.au


In article <4vupg6$ljf@goanna.cs.rmit.edu.au> Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU> writes:

> Hi,
> 
> One of our students has run into problems writing a Motif routine.
> The callback data is to be a string as follows..
> 
> 
> Xt.Intrinsic.XtAddCallback(
>                                  pb,
>                                  Motif.xmstrdefs.XmNactivateCallback,
>                                  hello_dialog_pkg.popup'access,
>                                  "Hello World");

You appear to be using the Ada95 bindings.  Good idea.  The client
data for XtAddCallback is not particularly well defined - in C land it
is something that fits in [pointer_size bits] which _typically_ means
it can be either a pointer or something like an integer.  The bindings
Xt.Intrinsic.XtPointer kinda sorta captures this by being a pointer to
a "null record" (a kinda sorta general undefined thingy).  In your
case it is clearly a pointer that is expected, but not one to
XtPointerRec (the designated type of XtPointer).  As you point out,
you can't really use access all String since String is unconstrained.
You could use an access all to some _constrained_ string.  But IMO that
sucks for various reasons, not the least of which is it is not flexible.

So, what you really want is just a "refinement" of XtPointerRec:

    subtype Call_Data_Type is Xt.Intrinsic.XtPointer;

    -- The information impl...
    --
    type Stg_Ref is access all String;
 
    type Info_Type is record
        Msg : Stg_Ref;
    end record;
 
    type Info_Ref is access all Info_Type;
 
    function To_CDT is new Unchecked_Conversion
        (Source => Info_Ref, Target => Call_Data_Type );
 
    msg  : aliased String := "The message";
    Info : aliased Info_Type := (Msg => Msg'Access);

    ...
    hello_dialog_pkg.popup'access,
    To_CDT(Info'Access));

This is much nicer since Info_Rec can contain anything and can be changed
to contain anything without having to rehack the conversions and whatnot
for the new information...

/Jon

-- 
Jon Anthony
Organon Motives, Inc.
1 Williston Road, Suite 4
Belmont, MA 02178

617.484.3383
jsa@organon.com





  parent reply	other threads:[~1996-08-28  0:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-08-27  0:00 Ada/Motif problem Dale Stanbrough
1996-08-27  0:00 ` Dale Stanbrough
1996-08-27  0:00   ` Michael K Rohan
1996-08-28  0:00     ` Larry Kilgallen
1996-08-29  0:00       ` Paul Hussein
1996-08-27  0:00 ` Larry Kilgallen
1996-08-28  0:00 ` David C. Hoos, Sr.
1996-08-28  0:00 ` Jon S Anthony [this message]
1996-08-29  0:00 ` Jon S Anthony
1996-08-29  0:00   ` Dale Stanbrough
1996-09-02  0:00     ` Sandy McPherson
  -- strict thread matches above, loose matches on Subject: below --
1996-08-28  0:00 G. Vincent Castellano
1996-08-28  0:00 W. Wesley Groleau (Wes)
replies disabled

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