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

How can i "clone" a TPanel?

1,922 views
Skip to first unread message

ladrillo

unread,
Sep 16, 2002, 5:51:37 AM9/16/02
to
Hi all

I'm developing a component with a method to clone Panels or other
components,
example:

I have into form1 a TPanel component with lot of controls over it (edits,
buttons
with events, etc...). Into Form1 i have a button that creates at runtime a
form and
does a showmodal of it. How can i create a panel into the new runtime form
copy
from the panel of Form1 (with exactly all the controls, events, ...)? I can
do it
easily setting the parent of the panel to the new form, but then the panel
dissapears
from Form1 and i dont wish this, i wish do an independent copy.

Thanks for all.


Robert Cerny

unread,
Sep 16, 2002, 2:47:43 PM9/16/02
to
Stream it:
S := TMemoryStream.Create;
S.WriteComponent(Panel1);
S.Position := 0;
F := TForm2.Create(Self);
P := TPanel.Create(F);
P.Parent := F;
S.ReadComponent(P);
S.Free;
F.ShowModal;
F.Free;

Naturally, put try..finally where required.


--
Robert

ladrillo wrote in message <3d85...@newsgroups.borland.com>...

ladrillo

unread,
Sep 17, 2002, 5:43:20 AM9/17/02
to
Hi robert and thanks, i have tested your code and i have good
and bad results. Your code runs OK, it copies the panel with its
properties, but not the components into it. I have into the Panel1
an Edit component and a Button with an event associated (shows
a test message), and your code doesn't copy this components.

I'm using Delphi 6, where is the problem? Thanks for all


Robert Cerny <robert.q...@neosys.xrs.qwe.si> escribió en el mensaje de
noticias am5g1...@neosys.xrs.si...

Gabriel B

unread,
Sep 17, 2002, 10:39:29 PM9/17/02
to
"ladrillo" <progra...@elladrillorojo.com> escribió en el mensaje
news:3d85...@newsgroups.borland.com...


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.386 / Virus Database: 218 - Release Date: 09/09/2002


John

unread,
Sep 18, 2002, 11:16:34 PM9/18/02
to
Look at the Controls property of TPanel. If I understand you correctly,
this is what you want.

"ladrillo" <progra...@elladrillorojo.com> wrote in message
news:3d883cf8$1...@newsgroups.borland.com...
> I need a generic function, i have lots of differents panels with
> differents components into them, so and due the system i'm developing
> i need a function or method to clone a entire panel, but not alway the
> same.
>
> Thanks
>
>
> Gabriel B <gbong...@hotmail.com> escribió en el mensaje de noticias
> 3d87...@newsgroups.borland.com...
> > Why not create a component with that Panel?

John

unread,
Sep 18, 2002, 11:16:34 PM9/18/02
to
Look at the Controls property of TPanel. If I understand you correctly,
this is what you want.

"ladrillo" <progra...@elladrillorojo.com> wrote in message
news:3d883cf8$1...@newsgroups.borland.com...
> I need a generic function, i have lots of differents panels with
> differents components into them, so and due the system i'm developing
> i need a function or method to clone a entire panel, but not alway the
> same.
>
> Thanks
>
>
> Gabriel B <gbong...@hotmail.com> escribió en el mensaje de noticias
> 3d87...@newsgroups.borland.com...
> > Why not create a component with that Panel?
> >

Johnnie

unread,
Sep 20, 2002, 6:33:58 AM9/20/02
to
On Феф 18 Уер 2002 11:42:01a , "ladrillo" <progra...@elladrillorojo.com>
wrote in news:3d883cf8$1...@newsgroups.borland.com

> I need a generic function, i have lots of differents panels with
> differents components into them, so and due the system i'm developing
> i need a function or method to clone a entire panel, but not alway the
> same.
>

There are a couple of ways to accomplish this.

1) create a function like the following.
Type
TPanelClass = Class of TPanel;
Function
CreatePanel(Panel:TPanelClass;AOwner:Tcomponent;AParent:TComponent):TPanel;
Begin
Result := Panel.create(AOwner);
Result.parent:=AParent;
end;

You call it like this
CreatePanel(TMyPanel,TMyform,TMyform);

Or
2) You have to register each panel class you
wish to be able to use create at runtime
using the registerclass procedure.
And then you use the findclass procedure
to retreive a class variable Typecast it
to a TPanel class and use it the same way
I have on the above function.

Regards
Johnnie.

0 new messages