How to save unknown components

I am saving the whole form trough:

var Stream: TMemoryStream;

  Stream:=TMemoryStream.Create;
  Stream.WriteComponent(MyForm);
  Stream.Seek( 0, soFromBeginning );  
  Stream.SaveToFile('MyForm.dfm');
  Stream.free;

But if I create a component in run time and instance of such component doesn't exists on this form in design time,
then I can't load back this form from file to app. I get error saying that such component doesn't exist.
How to save form with new components (I would like to load components to form in run time from dll's or so)?
TomazBAsked:
Who is Participating?
 
CesarioCommented:


you must register the components in the OnCreateEvent in you main Form:

<<I get error saying that such component doesn't exist. >>
Procedure tMyform.CreateForm ( ....);
Begin
  RegisterClass ( TNewcomponent );
  RegisterClass ( ......        );
End;
0
 
CesarioCommented:
Hi TomazB,

how do you insert the new Components at run Time ?

Parent ?
Owner  ?

Best Regards

Cesario
0
 
CesarioCommented:
Hi,

// To save the Form you can use  this Procedure
WriteComponentResFile('MyForm.dfm',MyForm);

Cesario

0
 
kretzschmarCommented:
or even registerclasses(...
0
 
TomazBAuthor Commented:
Yes, now I don't need to put "dumy" components on form to save and reload it. Is it possible to register component by it's name later - if I want to create instance of new component. like from dll?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.