Board index » cppbuilder » How to save text and array in one file?
Cris
![]() CBuilder Developer |
Cris
![]() CBuilder Developer |
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 |
Marcus P.
![]() CBuilder Developer |
2004-03-06 05:32:22 AM
Re:How to save text and array in one file?
Hi Cris,
"Cris" < XXXX@XXXXX.COM >wrote QuoteI have MDI application with two child forms, one contains TMemo QuoteIf I do, how to do this? 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. |