LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

The sample ini.prj which ships with CVI will not "Write" or "Modify" ini values

Can anyone help,

 

In the sample  ini.prj  which ships with CVI, at the  ini.c file description, it says "... This example illustrates how to use the Inifile instrument driver
to read, write, and modify INI-style tagged text files...".  When I run it I could only read the "Build.ini" file but could not Write to it or modify it.

Am I doing anything wrong? What should I do to be able to write to or modify the :Type" and "Value" fields of the GUI?

Thank you.

 

Bob

0 Kudos
Message 1 of 2
(4,079 Views)

You're right, the current version of this example offers you very limited possibilities to edit file content: it is specified in initial notes in the source file:

/*          This example opens an existing *.ini file and allows you to      */
/*          display, add, and remove sections and items from the inifile.    */

Having said this, I discourage you to edit build.ini file which is internal to CVI; you could examine a different file with .ini structure.

With little modifications you could also create a new file from scratch: updating FilenameBrowse function this way will permit you to create a new file and create sections and items in it, saving it at program end. You will still be limited to create only string items and not able to edit them, you'll need to update the example furthermore to do so.

 

int CVICALLBACK FilenameBrowse (int panel, int control, int event,
                                void *callbackData, int eventData1,
                                int eventData2)
{
    int		r;
    char tempFileName[MAX_PATHNAME_LEN];
	
    switch (event)
        {
        case EVENT_COMMIT:
            
            /* Ask user which file to open */
            if ((r = FileSelectPopupEx ("", "*.ini", "*.ini",
                                 "Specify INI file to open", VAL_OK_BUTTON,
                                 0, 0, tempFileName))
                != VAL_EXISTING_FILE_SELECTED)
                //return 0;                               
		goto new;

            /* Write the currently loaded file, if any, back out */
            if ((g_myInifile) && (g_changesMade))
                {
                if (ConfirmPopup ("Save Changes",
                                  "Do you want to save changes before opening "
                                  "a new file?"))
                    Ini_WriteToFile (g_myInifile, g_fileName);
                }    

            strcpy (g_fileName, tempFileName);
            
            /* Destroy the Inifile if it currently exists */
            if (g_myInifile)
                {
                Ini_Dispose (g_myInifile);
                g_myInifile = 0;
                }    
            g_changesMade = 0;
            
            /* Create a new Inifile object and read it from a file */
new:		if (!(g_myInifile = Ini_New (0)))
                {
                MessagePopup("Inifile","Error allocating memory for Inifile");
                goto Error;
                }   
            if (r == VAL_NEW_FILE_SELECTED)
            	strcpy (g_fileName, tempFileName);
			else {
				if (Ini_ReadFromFile (g_myInifile, g_fileName))
                {
                MessagePopup("Inifile","Error reading Inifile");
                goto Error;
                }   
			}
            SetCtrlVal (panel, PANEL_FILENAME, g_fileName);    
            UpdateUIR (panel);
            break;
        }
        
    return 0;
    
Error:        
    if (g_myInifile)
        Ini_Dispose (g_myInifile);
        

    return 0;
}

Despite these limitations, the example shows you the fundamentals of .ini file treatment with the IniFile instrument; with these framework you can develop your own strategy to save/read informations to disk in .ini-file format.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 2
(4,045 Views)