Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Loading/Saving Form state to file C++ Builder XE2

compmendcompmend Posts: 2Member
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(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.
Sign In or Register to comment.