Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to say data to a file

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How can I save to a file, say myfile.ini, some CheckBox settings from my application so when I re-open my application these CheckBox settings are restored.
 
Here is one possible way. You will need to include the
Code:
<iostream.h>
at the beginning of your program. Then open a file.
Code:
ofstream MyFile; // stream set up
MyFile.open(&quot;MyFile.ini&quot;, ios::out);

if (!MyFile)
{
     Application->MessageBox(&quot;Cannot open INI file.&quot;, &quot;File Error&quot;, MB_OK);
     return;
}
This will open a file named &quot;MyFile.ini&quot; for output and will also check to make certain the file was properly created. Depending on which version of libraries and compilers you are using, you may have to include the standard namespace.

After opening the file you can then send it some information.
Code:
if (RadioButton1->Checked == true)
    MyFile << &quot;RadioButton1 = true&quot; << endl;
else
    MyFile << &quot;RadioButton1 = false&quot; << endl;
Somewhere you need to do the opposite. Open the file for input and see if &quot;RadioButton1 = true&quot; and set
Code:
RadionButton1->Checked = true
.

Does this help? James P. Cottingham

I am the Unknown lead by the Unknowing.
I have done so much with so little
for so long that I am now qualified
to do anything with nothing.
 
hey, if its an .ini file, its much simpler than that.

//---------------------------------------------------------------------------

#include <vcl.h>
#include <IniFiles.hpp> // <-be sure to include this!!
#pragma hdrstop

#include &quot;Unit1.h&quot;
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource &quot;*.dfm&quot;
TForm1 *Form1;
TIniFile *ini; //initialize .ini file
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{

ini = new TIniFile (ChangeFileExt( &quot;TestCheck&quot;, &quot;.INI&quot; ) );

if (ini->ReadBool (&quot;CheckBox1&quot;, &quot;Checked&quot;, false)==false)
CheckBox1->Checked=false;
else
CheckBox1->Checked=true;


}
//---------------------------------------------------------------------------
void __fastcall TForm1::CheckBox1Click(TObject *Sender)
{
if (CheckBox1->Checked==true)
{
ini->WriteBool (&quot;CheckBox1&quot;, &quot;checked&quot;, true);
}
else
{
ini->WriteBool (&quot;CheckBox1&quot;, &quot;checked&quot;, false);
}

}
//---------------------------------------------------------------------------


you can also read strings, write strings, experiment, just type in ini-> and c what pops up. Cyprus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top