PDA

View Full Version : string data from an Xpanel form



ehallein
02-07-2005, 11:26 PM
I have an Xpanel form with various data fields. I can get the int and float data from the form using formget().

one of my field is a string, whenever I try to get this data i get nothing returned.

anyone know what needs to be done.

here is a code snippet:
int skipn =1;
char * baseName = "blabla";

(*lwxpf->formSet)(panID,F_NAME,baseName);
(*lwxpf->formSet)(panID,SKIP,&skipn);

(*lwxpf->post) ( panID );

skipn = (*lwxpf->formGet)(panID,SKIP);//this works fine
baseName = (*lwxpf->formGet)(panID,F_NAME);//this returns nothing


thanks

Lynx3d
02-10-2005, 09:54 AM
Eh...actually the "skipn" one should not work, or rather, produce unpredicatble results. When are you trying to read the returned string? After you destroyed the panel? I assume the pointers returned by formGet become invalid once you destroyed the panel (but the SDK doesn't give precise information about that...)

I think it should be more like:



int skipn =1, ok, *ival;
char * baseName = "blabla", *newName, *sval;

lwxpf->formSet(panID,F_NAME,baseName);
lwxpf->formSet(panID,SKIP,&skipn);

ok = lwxpf->post( panID );

if(ok) //the user pressed "ok" and not "cancel"
{
ival = lwxpf->formGet(panID,SKIP);
skipn = *ival;
sval = lwxpf->formGet(panID,F_NAME);
newName = strdup(sval); //needs #include <string.h>
}


Don't forget to free the memory of the string if you don't need it anymore.
(not that i never explicitly dereference a function pointer, it just confuses me, wouldn't work in C++ and is of course totally unnecessary :) )

ehallein
02-10-2005, 06:41 PM
Thanks that worked