dheller@cory.Berkeley.EDU (Dan Heller) (08/05/88)
I've been having a problem with XtGetValues actually getting some of my widget's values when called. For exmple, I would create a widget which has a char * field in it to represent a fairly dynamic string (e.g. its value changes rather frequently). I want to get the value of the string, so I call: Arg arg; char buf[SIZE]; XtSetArg(arg, XtNstring, buf); XtGetValues(widget, &arg, ONE); However, the buffer never gets filled with the value of the string. The funny thing is, this doesn't happen all the time -- some fields of the widget can be gotten just fine. I haven't been able to determine a pattern yet. A logical asumption at this time is that I shouldn't expect XtGetValues to strcpy() the value into the buffer, but rather to just set the value of the pointer passed to the value of the pointer of the char *. That means I'd have to pass the address of a char * variable. But this doesn't explain why it's not working for other variables. The only workaround I've found is to write a get_values_hook function, test the "name" attributes and set the "values" by hand. But this seems like it shouldn't be necessary. Dan Heller <island!argv@sun.com>
swick@ATHENA.MIT.EDU (Ralph R. Swick) (08/05/88)
I have to infer a lot from your description of your problem, as it's not clear to me whether you are using an existing widget (which may have bugs) or writing your own widget. I suspect the problem you are having is one that has confused many people. Resources of representation type XtRString are typedef'd as String; that is, char*. Thus the value of the resource is the pointer, not the contents of the string. When you do an XtGetValues, you'll get the pointer; no copying is done. So you really want something like: Arg arg; char *buf; XtSetArg(arg, XtNstring, &buf); XtGetValues(widget, &arg, ONE); So your diagnosis of the problem was correct. I can't guess why you may be having similar problems with other widget resources, without knowing the widgets involved. It is a common error to forget that XtGetValues requires the arglist to contain pointer(s) to the destination(s); the returned values are not stored into the arglist directly. If you happen to be using Xaw(AsciiString), then you're going to lose anyway, as GetValues(XtNstring) is broken in that widget.