Storing and retrieving control settings from/to a panel via a Structure

I want to store the settings in a panel to recall if the panel is closed and reopened. The panel attaches to a graph window. I have settled on using a Structure. I had hoped to store the entire structure into a defined UserData string for the graph window. If I understand correctly, I will have to step through each component in the structure, convert it to a string, and append the string into a keyword-value pair list. I have to invert the process to recover the values.

Does anyone have suggestions on an approach that is less tedious, inflexible, and error prone?

As a follow up comment, I am basically seeking the equivalent to StructPut/Get with /S to encode/decode an entire structure into/out of a string. In the meantime, perhaps this is a feature request to have flags StructPut/S/A and StructGet/S/A, whereby /A means to encode/decode the entire structure into/out of a string.

I am not interested in Load/SavePackagePreferences because I want to store the panel settings to the graph window.

Finally, it would also be great if implemented to have the StructGet/Put operations with /A to encode/decode character and string variables too, not just numbers.

This is IP 9 BTW.

It's frustrating not to be able to do what you describe. I assume that the goal is to to have panel information associated with an arbitrary number of graph windows, without saving any package clutter elsewhere.

I think that if you redefine the control structure to use char arrays instead of strings your approach will work. That's how strings are stored in package preference files.

perhaps something like this

static structure PanelStatusStructure
    STRUCT ControlValueStructure control1, control2
endstructure
 
static structure ControlValueStructure
    int16 type
    char ctrlName[100]
    double value
    char sval[100]
    STRUCT RGBColor rgb
    STRUCT RGBAColor rgba
    int16 selcol
endstructure
 
static function GetControlValue(string win, string controlName, STRUCT ControlValueStructure &s)
    ControlInfo/W=$win $controlName
    s.ctrlName = controlName
    s.type = v_flag
    switch (abs(V_Flag))
        case 3: // popup menu
            s.rgb.red = V_Red; s.rgb.green = V_Green; s.rgb.blue = V_Blue
            s.rgba.red = V_Red; s.rgba.green = V_Green; s.rgba.blue = V_Blue
            s.rgba.alpha = V_Alpha
        case 2: // checkbox
        case 4: // valdisplay
        case 5: // SetVariable
        case 7: // slider
        case 8: // tab
            s.value = v_value
            s.sval = s_value
            break
        case 11: // listbox
            s.value = v_value
            s.sval = s_value
            s.selcol = v_selcol
            break
    endswitch
end

 

note that when the help says

"The structure fields to be exported must contain only numeric data in either integer, floating point, or double precision format"

that includes char members, which are 1 byte integers.