Author: Jonas Bilinkevicius
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?
Answer:
I would use Read/ WriteComponentResFile with code similar to:
1 2 constructor TFrmPersistent.Create(AOwner: TComponent);
3 begin4 if FileExists('Persistent.xGS') then5 begin6 inherited CreateNew(AOwner);
7 ReadComponentResFile('Persistent.xGS', self);
8 self.Visible := false;
9 FormCreate(self);
10 end11 else12 inherited Create(AOwner);
13 end;
14 15 procedure TFrmPersistent.FormDestroy(Sender: TObject);
16 begin17 WriteComponentResFile('Persistent.xGS', self);
18 end;