Board index » cppbuilder » How to save text and array in one file?

How to save text and array in one file?


2004-03-06 03:43:42 AM
cppbuilder102
Hi,
I have MDI application with two child forms, one contains TMemo
and other TStringGrid. I would like to sane contents of both in
one file.
Can I do that?
If I do, how to do this?
If you know the answer please share.
Regards Cris
 
 

Re:How to save text and array in one file?

Hi Cris,
"Cris" < XXXX@XXXXX.COM >wrote
Quote
I have MDI application with two child forms, one contains TMemo
and other TStringGrid. I would like to sane contents of both in
one file.
Can I do that?
You can do anything.
Quote
If I do, how to do this?
Like anything there are numerous ways to skin a cat.
It really depends on exactly what you need to accomplish. If for example you
also need to read the contents of the file back into these two controls, you
may need a different appraoch than if you do not.
For starters, saving the contents of a TMemo into a file is super easy by
itself. Simply use the memos "Lines" property (which is a TStrings) and
save it to file like:
Memo1->Lines->SaveToFile("mytextfile.txt");
For the TStringGrid its slighly more complex. You will need to cycle through
the Cells property and put them all together into some memory structure that
you can save to file.
A super-simplified way to accomplish what you need might be to:
1) Create a new TStringList in memory using new.
2) use its Add() method to add the text of the TMemo:
MyNewStringList->Add(Memo1->Lines->Text);
3) Cycle through your grids cells and add each one to the stringlist.
4) Save the stringlist to file with its SaveToFile() method.
5) dont forget to delete the stringlist....
GL.
M.