From: gvc@ocsystems.com (G. Vincent Castellano)
Subject: Re: Ada/Motif problem...
Date: 1996/08/28
Date: 1996-08-28T00:00:00+00:00 [thread overview]
Message-ID: <1996Aug28.235051.12007@ocsystems.com> (raw)
> 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");
The specification of this routine is:
procedure XtAddCallback(
widget : Xt.Intrinsic.Widget;
callback_name: X.Strings.const_charp;
callback : XtCallbackProc;
closure : XtPointer);
The type XtPointer is not really a useful one, being a
private (access) type with no operations for setting it.
You are obliged to use Unchecked_Conversion to convert to
and from it.
A good choice in this case would be String_Access from the
package Ada.Strings.Unbounded. (Any access type will
probably work, since access types are generally all the
same size.)
function To_XtPointer is new Unchecked_Conversion(
Source => Ada.Strings.Unbounded.String_Access,
Target => Xt.Intrinsic.XtPointer );
Hi_String: constant Ada.Strings.Unbounded.String_Access
:= new String'("Hello World");
-- ...
Xt.Intrinsic.XtAddCallback( pb,
Motif.xmstrdefs.XmNactivateCallback,
hello_dialog_pkg.popup'access,
To_XtPointer( Hi_String ) );
BUT: be careful that the object you're specifying as callback
data is not local to a subprogram, else it will be garbage by
the time the callback is invoked. Declare it in a package spec
or body to be safe.
Also consider whether callback data is really useful. If it's
never going to change, you probably don't need it. I prefer to
play it safe and design callbacks so that only integers are
passed around, which I can then use to index into a table.
-----------------------------------------------------------------------
- G. Vincent Castellano, Sr. Software Engineer, OC Systems Inc -
- gvc@ocsystems.com :: X/Ada WWW => http://www.ocsystems.com/xada -
-----------------------------------------------------------------------
- "If virtual memory did not exist, it would -
- have become necessary for us to invent it." -
-----------------------------------------------------------------------
next reply other threads:[~1996-08-28 0:00 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
1996-08-28 0:00 G. Vincent Castellano [this message]
-- strict thread matches above, loose matches on Subject: below --
1996-08-28 0:00 Ada/Motif problem W. Wesley Groleau (Wes)
1996-08-27 0:00 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
1996-08-29 0:00 ` Jon S Anthony
1996-08-29 0:00 ` Dale Stanbrough
1996-09-02 0:00 ` Sandy McPherson
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox