C++ Builder

Moderators: Lundin
Number of threads: 518
Number of posts: 1158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Loading/Saving Form state to file C++ Builder XE2 Posted by compmend on 12 Jan 2013 at 9:16 PM
I hope someone can help me, I am currently working on a personal project where I need to save the position and content of dynamically created Images and Memos to a file, so that I can reload them when I restart the application.

I have been getting by creating an output file for each Image and Memo, along with a secondary file holding the relative information, such as the name, position, height, width, etc. and reading it back at the start of the application.

I tried porting code from Delphi to save the entire form as well as all components to a single file with the following test code.

This code works perfectly to save the form and it's settings to a file.

//Save the Form to a file
if(SaveDialog1->Execute())
{
TFileStream * FileStream;
TMemoryStream * MemStream;
MemStream = NULL;
FileStream = new TFileStream(SaveDialog1->FileName,fmCreate);
MemStream = new TMemoryStream;
MemStream->WriteComponent(dynamic_cast<TForm2 *>(ActiveMDIChild));
MemStream->Position = 0;
ObjectBinaryToText(MemStream, FileStream);
MemStream->Free();
FileStream->Free();
}

The problem I have is when I use the following code to create a new form with the information, it works perfectly if the saved form only contains TImage components, but, if I try to load a TMemo component, then the form is blank and I am not receiving an error. I have literally searched for over a week for an answer but, so far I have failed.


if(OpenDialog1->Execute())
{
TForm2 * Form2 = new TForm2(Application);
TFileStream * FileStream;
TMemoryStream * MemStream;
MemStream = NULL;
FileStream = new TFileStream(OpenDialog1->FileName,fmOpenRead);
MemStream = new TMemoryStream;
ObjectTextToBinary(FileStream, MemStream);
MemStream->Position = 0;
MemStream->ReadComponent(Form2);
Application->InsertComponent(Form2);
MemStream->Free();
FileStream->Free();
Form2->Show();
}

Keep in mind, I am not employed as a programmer, this is just a hobby for me, so my terminology may be off. Also, If you need anymore information to help me, let me know.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.