how to connect PtGetResource with a button?

I would like to input a number using PtText widget, and press a PtButton to assign this number to a variable which contains in code. The question is, do I have to add any callback between PtText and PtButton? And also how to use PtGetResource to assign the value to a variable? Thank you guys.

If you don’t put in any code, when you press the button, nothing happens. You need to use PhAB to put in an “Activate” callback on the button. In the callback you read the text widget’s data and puts it’s value into the variable.

An alternative is to use the Numeric-Integer widget. You don’t need a callback, but instead you would get this widget’s value whenever you want to use the variable. You could however put in a “Changed” callback if you want to know when the variable is changed.

PtGetResource is well documented in the online docs. It’s complicated because it handles different types of widget resources. The best docs are for PtGetResources(). The tricky part is that usually you send the address of a pointer variable. That’s two levels of indirection. The routine takes the address (a pointer) and fills in a pointer value, which you use to point at your data.

For example:if a text string widget is “datatext1”, and I would like to get its text string after press a button, I just add a code callback to this button, and in code write like this:

PtWidget_t *datatext1;
char *flags;
PtGetResource(datatext1, Pt_ARG_TEXT_STRING, &flags, 0);

so the text string in text widget just set to the flags? But I cannot compile it well, so any suggestions? Thank you.

Could you indicate the error you get. The code you posted looks ok to me.

Yes, what does “cannot compile it” mean?

Compile is good, and can run under PhAB.but when I type something in the PtText, then press the button, the whole program will close immediately, maybe add the wrong callback between code and widget, plz give me some suggestions.

In my code, “datatext_1” is the instance name of PtText and “flags” is the pointer to storage the name of txt file.

Compile is good, and can run under PhAB.But when I type something in the PtText, then press the button, the whole program will close immediately, maybe add the wrong callback between code and widget, plz give me some suggestions!

In my code, “datatext_1” is the instance name of PtText and “flags” is the pointer to storage the name of txt file.

I suggest you post your code.

Yech got it, like this
PtGetResource(ABW_data_file1, Pt_ARG_TEXT_STRING, &data_1, 0);

I dont know why but should add ABW before widget instance name.

If you look in the src director you will find .h files generated by PhAB. Each widget with an instance name generates a value ABW_xxxx.