Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Cloning TFrame

10 views
Skip to first unread message

Ken Revak

unread,
Jan 17, 2002, 3:36:19 PM1/17/02
to
I have a form that consists of a single copy of a frame and want to make
a number of duplicates at runtime. When I use the WriteComponent,
ReadComponent method of cloning the frame on read I get a
EComponentError saying that a component named pInput (a panel on the
frame) already exists.

Does this mean that the form is the owner of the frame's components?

Any suggestions on how to clone a duplicate of a frame on a form?


Code is:---------------------------------------
procedure TfrmInputStrips.Button1Click(Sender: TObject);
var
ms : TMemoryStream;
root : TControl;
i : integer;
ctl : TControl;
begin
inherited;

ms := TMemoryStream.Create;
try
root := isInputStrip; //isInputStrip is the frame I am trying to
duplicate
ms.WriteComponent(root);
for i := 2 to CMixerStripCount do begin
ms.Position := 0;
ctl := ms.ReadComponent(nil) as TControl;
ctl.Left := root.Left + root.Width;
ctl.Parent := root.Parent;
root := ctl;
end;
finally
ms.Free;
end;

end;
-----------------------------------------------

Ken Revak
Catalyst Systems

Peter Below (TeamB)

unread,
Jan 18, 2002, 4:36:13 PM1/18/02
to
In article <3C4735C3...@telusplanet.net>, Ken Revak wrote:
> I have a form that consists of a single copy of a frame and want to make
> a number of duplicates at runtime.

Do you need to copy user edited content? If not it would be much easier to
simply create some new instances of the frame. You need to set the Name
property of the existing frame to '' first to avoid "component with name
xxx already exists" errors and you also have to do this with every newly
created frame (or change the names to something different for each new
frame).

As to your current problem: you probably create an instance of the frame
class and then try to load it from the saved stream. The problem here is
that the frame is of cause created *with all components on it*, so you get
reams of errors on load. YOu need to create an *empty* frame using the
CreateNew constructor, then it should work. You will still need to set the
Name of the existing frame to empty, though. Note that doing so will Nil
the reference to the frame in the forms field!

Mh, i just noticed that TFrame does not have a CreateNew constructor,
unlike a form. How unfortunate. You will have to manually destroy all
components on the frame before you can reload it from the stream...

--
Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Use the newsgroup archives :
http://www.mers.com/searchsite.html
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be


Ken Revak

unread,
Jan 21, 2002, 10:45:18 AM1/21/02
to
Sigh.

I was hoping to be able to duplicate the frame complete with settings and
event handlers. This is done before for form is shown so user content is not
a concern.

I tried WriteDescendent and that allowed me to duplicate the visuals but the
handlers were not copied.

Seems I will have to duplicate the frames with code copying the properties and
event handlers, instead of duplicating the one properly set up in the window.

Thanks anyway.


Ken Revak
Catalyst Systems


0 new messages