Click here to Skip to main content
15,920,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to c++ and have inherited few c++ programs that read and write to the registry. Now it seems that they do not want to utilise the registry. Therefore they want to read and write to files. Ini files were suggested. I tried some code but no file gets created. Here is the code that I tried:
TIniFile *StartUp = new TIniFile("privs.ini");

Left = StartUp->ReadInteger("FormPos", "Left", 250);
Top = StartUp->ReadInteger("FormPos", "Top", 200);

delete StartUp;

Can anyone tell me why no file is created?
Posted
Updated 18-Jan-11 22:51pm
v2

Hi,

I see nothing wrong with your code. Are you sure that the file is not created? Maybe it just is not at the location you expect it to be?!

You could see this link for more information:
http://www.ww.functionx.com/bcb/howto/inifile.htm[^]
 
Share this answer
 
Comments
Espen Harlinn 19-Jan-11 5:57am    
5+ Good answer, you even know about Delphi/C++ Builder :)
JF2015 is definitely on the right track.

Use full path for your ini file. The way you do it now, probably means it ended up in the windows directory.

Update:

TIniFile *StartUp = new TIniFile("c:\\path\\to\\inifile\\privs.ini");

// get value or default if not found
Left = StartUp->ReadInteger("FormPos", "Left", 250); 
Top = StartUp->ReadInteger("FormPos", "Top", 200);

// Write to the ini file
StartUp->WriteInteger("FormPos", "Top", Top); 
StartUp->WriteInteger("FormPos", "Left", Left);

// Flush changes
StartUp->UpdateFile()


Call UpdateFile to flush buffered reads from and writes to the INI file to disk. UpdateFile is useful under Windows9x, but has no effect under Windows NT because NT does not buffer INI file reads and writes.

This version of UpdateFile is only available if the application is compiled for Windows

Regards
Espen Harlinn
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 19-Jan-11 11:00am    
That's good (my 5), but I hope you do not recommend hard-coded full path in software product, only for discovering the issue? :-)
Espen Harlinn 19-Jan-11 14:33pm    
No, not for production :)
Hope INI FILES[^] will give you an idea.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 19-Jan-11 11:01am    
Kasson, it may be good reference, but OP does not really have problem with that stuff.
 
Share this answer
 
The use oif INI files has long been deprecated and is no longer considered best practice. Try this Codeproject article - it utilizes xml data files to save settings:

XML Application Profile Class[^]
 
Share this answer
 
Comments
Member 9368218 9-Oct-12 1:52am    
Nice.. thnk x
I don't see you create a file anywhere in that code. You make a new class object with argument "privs.ini", but it's up to the constructor of that class what to do with it.

Could you please post the constructor function here?
 
Share this answer
 
Comments
Espen Harlinn 19-Jan-11 5:57am    
TIniFile is probably a VCL class, as in Delphi/C++ Builder
Espen : I'll try this tomorrow
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900