Board index » cppbuilder » Simple Form question

Simple Form question


2004-02-03 12:25:54 PM
cppbuilder17
I have what I believe is a 'simple' question regarding forms, and it's
one I used to know the answer to, but I'm trying to get my head back
into a BCB program after having done some Assembly work, so...
If I have a 'Child' form, when the form is created in BCB, it will be
given a global variable (for example, MyChild) as the name of the
pointer for the form. If the form is autocreated, this variable will be
used in the main routine with CreateForm, and if I create the from
myself at runtime, and only want one copy of the form to be present, I
can/should use it as well.
The 'MyChild' variable is thus used:
1. in the 'USEFORM' line of the main program
2. in the 'CreateForm' line of the main program
3. declared in the Form module itself
4. May be used when creating one instance 'on the fly' if not auto-created.
For cases where I might want to create multiple copies of a child, and
they don't relate to each other (but only to the parent), it would seem
pointless (and perhaps dangerous) to use the 'designated variable' for
any of the forms. If one doesn't need to keep track of them (directly),
one could simply create them on the fly without a named variable, by
simply setting the Owner during creation, and if one does need to keep
track of them, one can create an array of variable pointers (or even a
vector) to store the designated form pointers in.
For those cases where the 'individual' named variable is not used, is it
necessary to keep this in the program file? In other words, can the
'global variable' for that form be safely removed? Will the USEFORM
still process properly? Or is it best to leave it in place, even if the
variable will be unused?
I'd like to remove it so that I can provide better 'testing' of my
routines, in case the presence of the named variable is a requirement of
code in some modules that is overlooked, but I don't want to cause
myself a lot of grief in the process. If someone could add some
thoughts to this, I'd appreciate it.
David Erbas-White
 
 

Re:Simple Form question

"David Erbas-White" < XXXX@XXXXX.COM >wrote in message
Quote
In other words, can the
'global variable' for that form be safely removed? Will the USEFORM
still process properly?
Yes, it is safe to remove the default pointer from the .CPP file and its
corresponding extern from the .H file. I do it all the time.
The USEFORM() macro is defined in sysclass.h, and does nothing more than
define an additional external reference to the default form pointer, which
is then used by the auto-create code. If a definition for the form pointer
does not exist, then the extern declaration will simply have no effect.
However, don't remove the USEFORM() macro though. I believe it is used by
the IDE's project loader. If the USEFORM() macro isn't there, I think the
IDE will remove the form from the project the next time it gets loaded.
- Dennis
 

Re:Simple Form question

Quote
Yes, it is safe to remove the default pointer from the .CPP file and
its
corresponding extern from the .H file. I do it all the time.
You can remove all but the main form which is reference in WinMain.
Don't remember
to disable "Auto create forms".
 

{smallsort}

Re:Simple Form question

"eric67" < XXXX@XXXXX.COM >wrote in message
Quote
>Yes, it is safe to remove the default pointer from the .CPP file and
its
>corresponding extern from the .H file. I do it all the time.

You can remove all but the main form which is reference in WinMain.
Don't remember
to disable "Auto create forms".
Not true. You _can_ remove the main form if you want to, although it's
rarely necessary or desireable to do so. One such case would be, as Remy
and I discussed here recently, the case where the main form resides in a
DLL.
- Dennis