LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

remove/insert section

Solved!
Go to solution

hello,

 

I have the following problem.

 

1) if the button "delete" is pressed it should delete the last section from the IniFile
2) if the button "insert" is pressed it should insert an section between 2 phases in the IniFile

 

I have tried it already with Ini_RemoveSection with 1), however, this does not work.

the section was build

 

[SECTION_1] 

Item1

Item2

Item3

........

 

can somebody say to me like me the both buttons must program?

 

0 Kudos
Message 1 of 7
(4,012 Views)

Hello Axinia, you can find answers to most of your questions regarding ini files looking at the following example project installed on your disk: <cviSampleDir>\toolbox\ini.cws. (The folder were examples are stored can be located by looking at "Explore examples" option in CVI welcome page).

 

What you may need additionally is  how to locate a particular section to delete it, since you need to delete the last one. You can accomplish it by using:

 

index = Ini_NumberOfSections (handle);

Ini_NthSectionName (handle, index, sectionName);

Ini_RemoveSection (handle, sectionName);

 

this code locates the last section in the in-memory copy of the ini file, next retrieves its name and deletes it. After writing the IniText object to disk the section will be removed from the file too.

What do you observe when using Ini_RemoveSection so that you claim it does not work properly? Do you receive any error in your application?

 

To insert a section, simply use the appropriate Ini_Putxxx with the proper section name and it will be automatically created, but keep in mind that the positin in the physical file cannot be predicte, since it is determined by the instrument (I suppose by the order of sections in the in-memory object, which can be different from your logical vay of considering your data.



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 7
(4,005 Views)

hello,

I have just programmed it like you have said it, but the last section is not deleted. there also comes no error.
can you or everybody tell me what is wrong?

 


int CVICALLBACK DeleteStepCallback (int panel, int control, int event, void *callbackData,int eventData1, int eventData2)
{
        int index;
        char *ptrSectionNumber;
        IniText tmpDeleteStep = 0;
 

        switch (event)
        {
               case EVENT_COMMIT:
                          index = Ini_NumberOfSections( tmpDeleteStep );
                          Ini_NthSectionName( tmpDeleteStep, index, &ptrSectionNumber );
                          Ini_RemoveSection( tmpDeleteStep, ptrSectionNumber );
                      break;
        }
      return 0;
}

 

 

0 Kudos
Message 3 of 7
(3,980 Views)

Well, for the first thing you are working on a local IniText handle (tmpDeleteStep) on which you haven't created the corresponding object with Ini_New () nor you have loaded it from a file with Ini_ReadFromFile.

 

Additionally, you are not trapping the error conditions, so you are not likely to have a break popup error if you have not set Run >> Break on >> Library errors menu item or you have used DisableBreakOnLibraryErrors () anywere in your code before that callback. If you set a breakpoint on Ini_NumberOfSections you should see that the return value is -65, meaning "A NULL pointer was passed when a non-NULL pointer was expected", since tmpDeleteStep is initialized to 0 in the declaration. To trap library errors you must examine the return value of the functions, possibly using nullChk and errChk macros defined in the Programmer's Toolbox.

In case you are interested in it, you can look at my contribution on run-time error checking, which analizes how to trap an error condition and warn the operator with relevant informations about it.



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 4 of 7
(3,976 Views)

hello,

 

the problem is the same. if i set breakpoints the values are correctly, but the the last section wasn't delete.

 

 


int CVICALLBACK DeleteStepCallback (int panel, int control, int event, void *callbackData, int eventData1, int eventData2)
{
       int index;

       char *ptrSectionNumber; 
       IniText tmpDeleteStep;
 
       switch (event)
       {
              case EVENT_COMMIT:
                             tmpDeleteStep = Ini_New( 0 );
                             Ini_ReadFromFile( tmpDeleteStep, "c:\\My Documents\\LabWindows-CVI\\File.ini");

   

                              index = Ini_NumberOfSections( tmpDeleteStep );
                              Ini_NthSectionName( tmpDeleteStep, index, &ptrSectionNumber );
                              Ini_RemoveSection( tmpDeleteStep, ptrSectionNumber );
                          break;
           }
         return 0;
}

0 Kudos
Message 5 of 7
(3,971 Views)
Solution
Accepted by topic author Axinia
Try adding a Ini_WriteToFile at the end of the callback Smiley Wink


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 6 of 7
(3,969 Views)

a lot of many thanks for your help

you have helped me very much Smiley Happy

0 Kudos
Message 7 of 7
(3,965 Views)