10-28-2009 02:03 AM
10-28-2009 07:03 AM
do you mean in this format?
GetProjectDir(directoryPathName);
Ini_ReadFromFile (iniStationController, directoryPathName);
Ini_Dispose(iniStationController);
iniStationController=Ini_New( 0 );
Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
Ini_WriteToFile(iniStationController, iniFilePathName);
//system("notepad Config.ini");
10-28-2009 07:43 AM
10-28-2009 09:07 AM
darnell wrote:do you mean in this format?
GetProjectDir(directoryPathName);
Ini_ReadFromFile (iniStationController, directoryPathName);
Ini_Dispose(iniStationController);
iniStationController=Ini_New( 0 );
Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
Ini_WriteToFile(iniStationController, iniFilePathName);
//system("notepad Config.ini");
A little bit of logic would help...
GetProjectDir(directoryPathName);
Ini_ReadFromFile (iniStationController, directoryPathName);
How could you read from the file to IniFile object if you haven't created it yet?
Ini_Dispose(iniStationController);
If by chance a IniFile object would exist, here you have destroyed it (together with the content read from disk!)
iniStationController=Ini_New( 0 );
Ok, now the object (a brand new object) has been created, but filled with anything
Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
Ini_WriteToFile(iniStationController, iniFilePathName);
Here you are writing to disk only the 2 elements filled in those lines.
Correct logic:
IniText iniStationController = 0;
// Other code here (af any)
GetProjectDir(directoryPathName);
// Dispose an existing object, if any
if (iniStationController > 0) Ini_Dispose(iniStationController);
// Create a new object
iniStationController = Ini_New( 0 );
// Fill with content from file on disk
Ini_ReadFromFile (iniStationController, directoryPathName);
// Update some field
Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
// Write the updated content to disk
Ini_WriteToFile(iniStationController, iniFilePathName);
// Dispose the object after using it
if (iniStationController > 0) Ini_Dispose(iniStationController);
10-28-2009 09:50 AM
correct, I found out the problem, it happens everytime. its like you do something real simple and straight point, but its hard to pin point the
the simple misstake you made. dont get me wrong your logic is correct to a certain , but when I you call the Ini_
GetProjectDir(directoryPathName);
MakePathname(directoryPathName,CONFIG_FILE2,iniFilePathName);
Ini_Dispose(iniStationController);
iniStationController=Ini_New( 0 );
//Ini_ReadFromFile (iniStationController,directoryPathName);//////////////this line is the misstake, the second parameter should be iniFilePathName
Ini_ReadFromFile (iniStationController,iniFilePathName);correct line
Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
Ini_WriteToFile(iniStationController, iniFilePathName);
Ini_Dispose(iniStationController);
//system("notepad Config.ini");
now im going to put in my test , thanks roberto for your help
10-28-2009 09:57 AM
// Other code here (af any)
GetProjectDir(directoryPathName);
// Dispose an existing object, if any
if (iniStationController > 0) Ini_Dispose(iniStationController);///// can you explain the reason for the greater >0 check?
// Create a new object
iniStationController = Ini_New( 0 );
// Fill with content from file on disk//////// can you explain the fill with content with file on disk?
Ini_ReadFromFile (iniStationController, directoryPathName);
// Update some field
Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
// Write the updated content to disk
Ini_WriteToFile(iniStationController, iniFilePathName);
// Dispose the object after using it
if (iniStationController > 0) Ini_Dispose(iniStationController);//I guess my problem is understanding the dispose function!!!
I just need a lil assistance.
10-28-2009 10:05 AM
411, 32 Operands of > have illegal types 'IniText' and 'int'.
im getting this error
when i use the this test
if(iniStationController > 0)
{
Ini_Dispose(iniStationController);
}
10-28-2009 10:21 AM
// Other code here (af any)
GetProjectDir(directoryPathName);
// Dispose an existing object, if any
if (iniStationController > 0) Ini_Dispose(iniStationController);
///// can you explain the reason for the greater >0 check?
Sorry, my fault: variable is initialized to 0 and populated by Ini_New, which either returns NULL or a valid handle (iniText variables are really a pointer to an object in memory). The correct instruction is
if (iniStationController) Ini_Dispose(iniStationController);
// Create a new object
iniStationController = Ini_New( 0 );
// Fill with content from file on disk
Ini_ReadFromFile (iniStationController, directoryPathName);
//////// can you explain the fill with content with file on disk?
With ReadFromFile function the memory object is populated by the content read fromt the file. After this instruction you can query the elements read from disk with the appropriate Ini_Get functions
// Update some field
Ini_PutInt(iniStationController, "DAS", "X_BORESIGHT", offSetXposition);
Ini_PutInt(iniStationController, "DAS", "Y_BORESIGHT", offSetYposition);
// Write the updated content to disk
Ini_WriteToFile(iniStationController, iniFilePathName);
// Dispose the object after using it
if (iniStationController) Ini_Dispose(iniStationController);
//I guess my problem is understanding the dispose function!!!
Like in any other case, you need to free the memory allocated by some particular object when you no longer need it: this is done by Ini_Dispose function which properly gets rid of all the memory allocated.
In case you want to study it, the inifile instrument is deployed at code level, that is you can find on your hard disk both the include and the source file of this instrument (they are located in <cvidir>\toolslib\toolbox folder), so you can look at it and understand how it's working
10-28-2009 01:18 PM
Darnell:
Going back to your comment "for some reason the ini_new erases all my sections and input only the section I requested":
I know Roberto already underlined what Ini_New() does, and it sounds like you got past that problem, but here's a more general suggestion. If you don't understand the behavior of a CVI library function you're using in your program, study the help for that function. CVI help is pretty good, but, just like with C code, you need to read it pretty carefully to understand it.
10-28-2009 07:55 PM