From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6c7be346cfa17c37 X-Google-Attributes: gid103376,public From: gvc@ocsystems.com (G. Vincent Castellano) Subject: Re: Ada/Motif problem... Date: 1996/08/28 Message-ID: <1996Aug28.235051.12007@ocsystems.com>#1/1 X-Deja-AN: 177132272 organization: OC Systems, Inc. newsgroups: comp.lang.ada Date: 1996-08-28T00:00:00+00:00 List-Id: > 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." - -----------------------------------------------------------------------