Stream forms to and from disk (Views: 100)


I have a form that creates an advanced SQL string and I am trying to stream the entire form (TAdvanced) to disk in order to save the state of the form, and then be able to easily recall it later without having to decode the SQL string. However, after successfully (I think) streaming it to disk, I get the error "A component named PageControl1 already exists". I have tried all kinds of variations on this, but there always seems to be some conflict - either TAdvanced can't be assigned to TAdvanced or the current, or others. Any suggestions would be appreciated. Do I need to manually iterate through the components of the form and write each one in turn to the stream?


I would use Read/ WriteComponentResFile with code similar to:

constructor TFrmPersistent.Create(AOwner: TComponent);
  if FileExists('Persistent.xGS') then
    inherited CreateNew(AOwner);
    ReadComponentResFile('Persistent.xGS', self);
    self.Visible := false;
    inherited Create(AOwner);

procedure TFrmPersistent.FormDestroy(Sender: TObject);
  WriteComponentResFile('Persistent.xGS', self);

<< Back to main page