Borland C++ XE2 Question

I hope someone can help me, I am currently working on a project where I need to save the position and content of dynamically created Images and Memos to a file.

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 save and 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();
}
Last edited on
Topic archived. No new replies allowed.