Board index » cppbuilder » Copying one form+controls etc into another

Copying one form+controls etc into another

I have a complex form which I'm streaming out to an Ansistring. I've written
some code which allows me to create a new "duplicate" of this form as a
seperate entity. It is getting a bit too complex and seems to be failing an
unusual times (like complaining thet TMemo/TLabe etc arte not registered
with the streaming system (not true obviously).

Can anyone tell me if there is a "correct" way of "duplicating" a form with
all it's sub controls and everything.

(My kludge handles some dynamic controls and stuff, but for now I only
require the form and its implicit (or designed in) controls).
(I'm currently using a combination of

        pms->WriteComponent(c);
        pms->Seek(0, soFromBeginning);
        ObjectBinaryToText(pms, pss);

and the reverse..

Thanks

JB

 

Re:Copying one form+controls etc into another


On Fri, 22 Mar 2002 00:26:20 -0000, "John Biddiscombe"

Quote
<no.jbiddisco...@skippingmouse.spam.uk> wrote:
>Can anyone tell me if there is a "correct" way of "duplicating" a form with
>all it's sub controls and everything.

Sorry if this is a dumb question, but why can't you simply create
another form of the same class? Do you need to modify its controls in
some major way?

I would imagine that the VCL's inherent component streaming facilities
would make this easy, assuming that they're usable from C++.

Re:Copying one form+controls etc into another


Quote
> >Can anyone tell me if there is a "correct" way of "duplicating" a form
with
> >all it's sub controls and everything.

> Sorry if this is a dumb question, but why can't you simply create
> another form of the same class? Do you need to modify its controls in
> some major way?

If I create a new form of the same type (or frame which I also need to
copy), then all is well, but the component properties, like scroller
positions, edit texts, colours of things are all lost.

I need to make a perfect copy of everything.

In addition, I then want to add in support for a perfect copy of all my
dynamically allocated controls on the form or frame too.

Quote
>I would imagine that the VCL's inherent component streaming facilities
>would make this easy, assuming that they're usable from C++.

This is exactly the question I'm trying to find the answer to. I have a
mostly working implementation, using the streaming system, but it is not
simple or straightforward and contains many special cases. The vcl streaming
must have an easy way. I would like to know what it is.

JB

Re:Copying one form+controls etc into another


On Fri, 22 Mar 2002 12:31:34 -0000, "John Biddiscombe"

Quote
<no.jbiddisco...@skippingmouse.spam.uk> wrote:
>This is exactly the question I'm trying to find the answer to. I have a
>mostly working implementation, using the streaming system, but it is not
>simple or straightforward and contains many special cases. The vcl streaming
>must have an easy way. I would like to know what it is.

I doubt you're going to get much help with that here, because BCBers
tend to regard the trickier internals of the VCL, and the extensions
which mimic the required OP features, such as __classid, as a black
box. You need a detailed explanation of how form streaming works from
a Delphi guru.

Re:Copying one form+controls etc into another


"John Biddiscombe" <no.jbiddisco...@skippingmouse.spam.uk> wrote

Quote
> I have a complex form which I'm streaming out to an Ansistring. I've
written
> some code which allows me to create a new "duplicate" of this form as a
> seperate entity. It is getting a bit too complex and seems to be failing
an
> unusual times (like complaining thet TMemo/TLabe etc arte not registered
> with the streaming system (not true obviously).

Before loading classes from stream You should register used classes manually
via RegisterClass, or preferably use RegisterClasses.
You can also take a look at TCustomForm::TCustomForm(TComponent* AOwner, int
Dummy) in help. I never used it, but may be it will help You in Your quests.

--
--- With best wishes, Kirill.
 * open mind for a.different view (c)

Re:Copying one form+controls etc into another


Quote
> You can also take a look at TCustomForm::TCustomForm(TComponent* AOwner,
int
> Dummy) in help. I never used it, but may be it will help You in Your

quests.

No good as it's only implemented for TCustomForm and subclasses. I want
TFrame etc and other controls to be directly copyable (like Assign) but for
arbitrary complexity. Anyway, I think I've found a fix for some of my
trouble now...

Thanks.

JB

Other Threads