•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 391,563 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,728 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 11224 | Replies: 3
![]() |
•
•
Join Date: Jun 2004
Posts: 604
Reputation:
Rep Power: 6
Solved Threads: 6
Hi Everyone,
I need some help in saving a file in the rich text edit control i have. Basically i have one button and richedit control on a form and what i need is the contents of the entire rich edit control to be passed to the saveas common dialog to be saved onto thee disk. One more thing to note is that my rich edit also contains pictures and text. Can anyone tell me how this is done or show me the codings of how this is done. So far this all that i have gotten so far.
Void CDialogsDlg::onSaveAs ()
{
CFileDialog m_ldFile(false);
if(m_ldFile.DoModal = = IDOK)
{
//This is the part i do not know how to save the entire contents
// of the rich edit
}
}
Someone please help me . My e-mail is freesoft_2000@yahoo.com
Thank You
Yours Sincerely
Richard West
I need some help in saving a file in the rich text edit control i have. Basically i have one button and richedit control on a form and what i need is the contents of the entire rich edit control to be passed to the saveas common dialog to be saved onto thee disk. One more thing to note is that my rich edit also contains pictures and text. Can anyone tell me how this is done or show me the codings of how this is done. So far this all that i have gotten so far.
Void CDialogsDlg::onSaveAs ()
{
CFileDialog m_ldFile(false);
if(m_ldFile.DoModal = = IDOK)
{
//This is the part i do not know how to save the entire contents
// of the rich edit
}
}
Someone please help me . My e-mail is freesoft_2000@yahoo.com
Thank You
Yours Sincerely
Richard West
•
•
Join Date: May 2004
Location: Egypt - Cairo
Posts: 124
Reputation:
Rep Power: 5
Solved Threads: 2
Introduction
---------------
The Visual Component Library (VCL) provides various built-in classes to perform file processing. Most of the features are provided through the TFileStream class. To perform file streaming using this class, first declare its instance using its constructor whose syntax is:
The first argument of this constructor is the name (or path) of the file you are dealing with. If the file does not exist or it cannot be accessed (opened or saved) for any reason, the compiler would throw an error and stop the action.
The second action, Mode, specifies what you are trying to do with the file.
The TFileStream class is conceptually designed to deal with the contents of one or more controls. Therefore, instead of concerning yourself with the values of controls, TFileStream would consider the change that affect a control on behalf of the user, which mostly is its contents. When saving a file, TFileStream faithfully gets the contents of all controls as you wish and saves them in one file. If opening a file, TFileStream locates the content of each file and restores it. Based on this, TFileStream is appropriate for VCL objects and usually its files should not mixed with non-VCL controls.
Saving Controls Contents
In order to save the contents of controls, first declare a pointer to TFileStream using its constructor and specify where the file would be saved. You can specify this path directly in the constructor if you know exactly where the file should be located. This can be done if you are writing a program that stores the default file at a specific location and you know where the file should be saved. Otherwise, you can use the SaveDialog control to let the user specify where to save the file.
When saving a file, the Mode argument of the constructor can be passed as one of the following constants:
Write Mode Description
fmCreate If the user is saving a new file, this is used to save it as new
fmOpenWrite This is used to save a file as new. If the file was previously saved and reopened, this mode would erase its previous contents and fill it with the new data
fmOpenReadWrite If the file already existed, this can be used to save a file that has been modified. Otherwise it can be used to create a new file
When it is possible that other people or application would try accessing the same file at the same time, the following constants can be used to manage the sharing of files:
Share Mode Description
fmShareExclusive Only the current application can access the file
fmShareDenyWrite The file can be opened by other applications but they cannot modify its contents
fmShareDenyRead The file can be modified by other applications but they cannot open it
fmShareDenyNone There is no restriction on what the other applications can do with the current file
To combine these two mode for the Mode argument, you use the bitwise OR operator |
Imagine you create a form equipped with a Memo and an Edit controls:
Here is an example of saving the contents of both controls to a file:
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
Loading Controls Contents
When saving the contents of controls using TFileStream, the file is arranged so the class can locate data for each object. Based on this, you can use TFileStream to open a file that was created with this class. To do this, once again, declare a pointer to TFileStream and initialize the file using the constructor. If you already know where the file is located, you can simply provide it to the constructor. Otherwise, you can use the Open dialog box and let the user select the file.
When opening a file, you can use one of the following modes as the Mode argument:
Read Mode Description
fmOpenRead This is used to open a file but the user cannot modify and then save it.
fmOpenReadWrite This allows opening an existing file, modifying, and saving it.
You can combine this mode with one of the above share modes using the bitwise OR operator. Here is an example from the same above form design:
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
---------------
The Visual Component Library (VCL) provides various built-in classes to perform file processing. Most of the features are provided through the TFileStream class. To perform file streaming using this class, first declare its instance using its constructor whose syntax is:
__fastcall TFileStream(const AnsiString FileName, Word Mode);
The second action, Mode, specifies what you are trying to do with the file.
The TFileStream class is conceptually designed to deal with the contents of one or more controls. Therefore, instead of concerning yourself with the values of controls, TFileStream would consider the change that affect a control on behalf of the user, which mostly is its contents. When saving a file, TFileStream faithfully gets the contents of all controls as you wish and saves them in one file. If opening a file, TFileStream locates the content of each file and restores it. Based on this, TFileStream is appropriate for VCL objects and usually its files should not mixed with non-VCL controls.
Saving Controls Contents
In order to save the contents of controls, first declare a pointer to TFileStream using its constructor and specify where the file would be saved. You can specify this path directly in the constructor if you know exactly where the file should be located. This can be done if you are writing a program that stores the default file at a specific location and you know where the file should be saved. Otherwise, you can use the SaveDialog control to let the user specify where to save the file.
When saving a file, the Mode argument of the constructor can be passed as one of the following constants:
Write Mode Description
fmCreate If the user is saving a new file, this is used to save it as new
fmOpenWrite This is used to save a file as new. If the file was previously saved and reopened, this mode would erase its previous contents and fill it with the new data
fmOpenReadWrite If the file already existed, this can be used to save a file that has been modified. Otherwise it can be used to create a new file
When it is possible that other people or application would try accessing the same file at the same time, the following constants can be used to manage the sharing of files:
Share Mode Description
fmShareExclusive Only the current application can access the file
fmShareDenyWrite The file can be opened by other applications but they cannot modify its contents
fmShareDenyRead The file can be modified by other applications but they cannot open it
fmShareDenyNone There is no restriction on what the other applications can do with the current file
To combine these two mode for the Mode argument, you use the bitwise OR operator |
Imagine you create a form equipped with a Memo and an Edit controls:
Here is an example of saving the contents of both controls to a file:
//---------------------------------------------------------------------------
void __fastcall TForm1::btnSaveClick(TObject *Sender)
{
// Decalre a pointer to TFileStream
TFileStream *FStream;
// Let the user call the Save Dialog
if( SaveDialog1->Execute() )
{
// Use the constructor of the TFileStream to create a file
try {
FStream = new TFileStream(SaveDialog1->FileName, fmCreate);
// In the pointer to FStream, add the contents of the Memo
FStream->WriteComponent(Memo1);
// and the content of the Edit controls
FStream->WriteComponent(Edit1);
}
__finally
{
// Since the pointer was created, delete it,
// whether it was used or not
delete FStream;
}
}
}Loading Controls Contents
When saving the contents of controls using TFileStream, the file is arranged so the class can locate data for each object. Based on this, you can use TFileStream to open a file that was created with this class. To do this, once again, declare a pointer to TFileStream and initialize the file using the constructor. If you already know where the file is located, you can simply provide it to the constructor. Otherwise, you can use the Open dialog box and let the user select the file.
When opening a file, you can use one of the following modes as the Mode argument:
Read Mode Description
fmOpenRead This is used to open a file but the user cannot modify and then save it.
fmOpenReadWrite This allows opening an existing file, modifying, and saving it.
You can combine this mode with one of the above share modes using the bitwise OR operator. Here is an example from the same above form design:
//---------------------------------------------------------------------------
void __fastcall TForm1::btnOpenClick(TObject *Sender)
{
TFileStream *FStream;
if( OpenDialog1->Execute() )
{
try {
FStream = new TFileStream(OpenDialog1->FileName,
fmOpenRead | fmShareExclusive);
FStream->ReadComponent(Memo1);
FStream->ReadComponent(Edit1);
}
__finally
{
delete FStream;
}
}
} Real Eyes Realize Real Lies
•
•
Join Date: May 2004
Location: Egypt - Cairo
Posts: 124
Reputation:
Rep Power: 5
Solved Threads: 2
Everyone is familar is the Common Dialog - File Open/Save control in Windows, you use it everyday. This script shows you how to script the Common Dialog control and put it to work for you.
--------------------------------------------------------------------------------------
Note: This script will run on system's with the Microsoft Controls properly installed. If your machine has virtually any of Microsoft's development tools installed, you probably have these controls. I have yet to find an easy way to distribute these, I am open to suggestions.
--------------------------------------------------------------------------------------
Note: This script will run on system's with the Microsoft Controls properly installed. If your machine has virtually any of Microsoft's development tools installed, you probably have these controls. I have yet to find an easy way to distribute these, I am open to suggestions.
// Create the Objectcd = new ActiveXObject("MSComDlg.CommonDialog");
// Set file filtercd.Filter = "All Files(*.*)|*.*|JScript Files(*.js)|*.js";cd.FilterIndex = 2;
// Must set MaxFileSize. Otherwise you will get an errorcd.MaxFileSize = 128;
// Show it to usercd.ShowOpen();
// Retrieve file + pathfile = cd.FileName;
// If the user does enter file exitif ( !file )
{ WScript.Echo("You must enter a file name");
WScript.Quit(0);
}
else
{
WScript.Echo("The user selected:\n" + file );
} Real Eyes Realize Real Lies
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- how can i implement a string from Jtextfield and saving it to a file (Java)
- Quark upgrade lost file (was: please... im begging here, someone help!!) (Mac Software)
- Saving a file (Java)
Other Threads in the C++ Forum
- Previous Thread: don't understand
- Next Thread: Is ifs is a member function of ifstream class


Linear Mode