 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Corinna Guest
|
Posted: Mon Sep 12, 2005 4:34 pm Post subject: newbie question: Inheriting from a form? |
|
|
Can I have a form which has components on it be a parent class for other
forms? I have 3 different type of notes that a user can enter. They all
have a memo box, a date, space for a name, address, etc. Each type of note
also has specific data that goes along with it. This sounds like a candidate
for inheritance (or perhaps an abstract class). In addition, there is some
common logic in processing these notes, such as print, print preview, save.
I would still like the convenience of using the form designer, as well as
the data aware controls. (I'm still wrapping my mind around the whole OPF
thing, and I still have to produce something in the meantime )
Is this possible? I suspect I have to give up the convenience of the form
designer...
-Corinna
|
|
| Back to top |
|
 |
Peter Morris [Droopy eyes Guest
|
Posted: Mon Sep 12, 2005 4:44 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
File->New->Other (I think)
Then select the tab that has the same name as your application [MyApp]
From the list select the base form, then in the radio box at the bottom
select "inherit". Now you have it.
For an existing form you can change inheritance like so
1) Change "MyForm = class(TForm)" to "MyForm = class(MyBaseForm)"
2) On the form press ALT+F12 to view the form as text, chang the first word
from "object" to "inherited"
3) ALT+F12 to switch back to form view
But remember, composition is more powerful than inheritance It might
prove more flexible to have TFrame controls and drop them onto forms
instead.
--
Pete
====
ECO Modeler, Audio compression components, DIB graphics controls,
FastStrings
http://www.droopyeyes.com
Read or write articles on just about anything
http://www.HowToDoThings.com
My blog
http://blogs.slcdug.org/petermorris/
|
|
| Back to top |
|
 |
Iman L Crawford Guest
|
Posted: Mon Sep 12, 2005 7:47 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
"Peter Morris [Droopy eyes software]" <pete (AT) NO_droopyeyes_SPAM (DOT) com>
wrote in news:4325b019 (AT) newsgroups (DOT) borland.com:
| Quote: | it might prove more flexible to have TFrame controls and drop them
onto forms instead.
|
I would go with TFrames too.
--
Iman
|
|
| Back to top |
|
 |
Scott Roberts Guest
|
Posted: Mon Sep 12, 2005 11:15 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
"Corinna" <schultz (AT) harlingen (DOT) isd.tenet.edu> wrote
| Quote: | Can I have a form which has components on it be a parent class for other
forms?
|
Yes. See Peter's instructions.
| Quote: | Is this possible? I suspect I have to give up the convenience of the form
designer...
|
Nope. You can still use the form designer.
The only caveat I'll throw out is that it would be a *great* idea to get
your base form set in stone before you start inheriting from it. Going back
and changing the base form after you've got 30 inherited forms will probably
give you trouble. Changing the *code* is no problem, but changing the
controls/visual properties is trouble.
|
|
| Back to top |
|
 |
Corinna Guest
|
Posted: Tue Sep 13, 2005 4:32 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
Do you mean that if you change the controls in the base form, the changes
don't propagate down? Then it's not really inheritance, it's just using the
base form as a template...
It sounds like you're saying that the pas part of the unit is properly
inherited, but the dfm part isn't.
-Corinna
"Scott Roberts" <scott.roberts (AT) no-spam-intelebill (DOT) com> wrote
| Quote: | The only caveat I'll throw out is that it would be a *great* idea to get
your base form set in stone before you start inheriting from it. Going
back
and changing the base form after you've got 30 inherited forms will
probably
give you trouble. Changing the *code* is no problem, but changing the
controls/visual properties is trouble.
|
|
|
| Back to top |
|
 |
Anderson Farias Guest
|
Posted: Tue Sep 13, 2005 5:17 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
| Quote: | Do you mean that if you change the controls in the base form, the changes
don't propagate down?
|
I don't think he meant that, as if you change the base form (controls and so
on..) the inherited forms are also changed as well.
Regards
|
|
| Back to top |
|
 |
Peter Morris [Droopy eyes Guest
|
Posted: Tue Sep 13, 2005 5:49 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
| Quote: | Do you mean that if you change the controls in the base form, the changes
don't propagate down? Then it's not really inheritance, it's just using
the
base form as a template...
It sounds like you're saying that the pas part of the unit is properly
inherited, but the dfm part isn't.
|
If you try it (takes 2 minutes) you will see that this is not the case at
all.
The problem is this
(BaseForm)
Edit1
Edit2
(ChildForm)
[Edit1]
[Edit2]
Checkbox1
Now go back to the base form and add Edit3 beneath Edit2. Look back at
ChildForm and you will see that Checkbox1 and Edit3 both occupy the same
space. This is why it can be a pain to update the main form. Also, if you
delete controls from the main form you need to ensure
A) All descendant forms are open
B) You change something on all descendant forms so that they get saved
otherwise when you open a child form at runtime you will get an exception
that a control is missing.
Composition is better :-)
--
Pete
====
ECO Modeler, Audio compression components, DIB graphics controls,
FastStrings
http://www.droopyeyes.com
Read or write articles on just about anything
http://www.HowToDoThings.com
My blog
http://blogs.slcdug.org/petermorris/
|
|
| Back to top |
|
 |
Scott Roberts Guest
|
Posted: Tue Sep 13, 2005 6:55 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
"Peter Morris [Droopy eyes software]" <pete (AT) NO_droopyeyes_SPAM (DOT) com> wrote in
message news:432710da (AT) newsgroups (DOT) borland.com...
| Quote: | Also, if you
delete controls from the main form you need to ensure
A) All descendant forms are open
B) You change something on all descendant forms so that they get saved
|
Exactly.
I don't remember the *exact* other problems any more either, but there were
some related to moving/aligning controls on the base form. Any time I
visually change a base form (which I haven't in years) I open all descendant
forms and re-save them then "Build All" (then hold my tongue on the left
side of my mouth and spin in my chair twice). That usually does the trick.
Seriously, though. Form inheritance isn't all that bad if you what you
really want is common *functionality* in the forms instead of common
*visuality*. Of course, there are easier ways to implement common
functionality, so maybe visual inheritance isn't so grand after all. If I
had it to do over again, I'd probably take Peter's advice and do composition
instead of inheritance.
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Tue Sep 13, 2005 10:55 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
Corinna wrote:
| Quote: | Do you mean that if you change the controls in the base form, the
changes don't propagate down? Then it's not really inheritance, it's
just using the base form as a template...
|
The problem is, since the inherited controls are available to you on the
design surface, it is possible to alter them in the descendant. *Then* if
you go back to the ancestor to make a change, what should Delphi do?
So, as long as no properties of an inherited control are changed in a
descendant, changes to the ancestor will immediately be respected in the
descendant. If any properties have been changed though, then the changed
controls in that descendant will not reflect subsequent changes in the
ancestor (this is all on a control by control and descendant by desccendant
basis). In most cases this is the correct behaviour (and only reasonable one
really), but it can be a pain too if you want to see ancestor changes. There
is a context menu item to revert a changed descendant control.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
It used to be that other people's achievements were considered an
inspiration, not a grievance.
|
|
| Back to top |
|
 |
Corinna Guest
|
Posted: Wed Sep 14, 2005 1:09 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
Hmmm. I see...
If I were to do composition, then would that entail:
1. Create a panel (descendant?) with the characteristics I want (memos,
checkboxes, etc), and the behaviors I want.
2. In order to manipulate it visually, install it as a component in the
palette
3. Create a new form, and use this panel as a component in the form.
4. Customize.
Is that right? I've never done this before...
-Corinna
"Wayne Niddery [TeamB]" <wniddery (AT) chaffaci (DOT) on.ca> wrote
| Quote: | The problem is, since the inherited controls are available to you on the
design surface, it is possible to alter them in the descendant. *Then* if
you go back to the ancestor to make a change, what should Delphi do?
So, as long as no properties of an inherited control are changed in a
descendant, changes to the ancestor will immediately be respected in the
descendant. If any properties have been changed though, then the changed
controls in that descendant will not reflect subsequent changes in the
ancestor (this is all on a control by control and descendant by
desccendant
basis).
|
|
|
| Back to top |
|
 |
Anderson Farias Guest
|
Posted: Wed Sep 14, 2005 3:26 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
| Quote: | 1. Create a panel (descendant?) with the characteristics I want (memos,
checkboxes, etc), and the behaviors I want.
|
More likelly to be a TFrame that you'll be creating (instead of a Tpanel)
Regards
|
|
| Back to top |
|
 |
Wayne Niddery [TeamB] Guest
|
Posted: Wed Sep 14, 2005 3:36 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
Corinna wrote:
| Quote: | If I were to do composition, then would that entail:
1. Create a panel (descendant?) with the characteristics I want
(memos, checkboxes, etc), and the behaviors I want.
2. In order to manipulate it visually, install it as a component in
the palette
3. Create a new form, and use this panel as a component in the form.
4. Customize.
|
Use Frames, not panels. Frames give you the design capabilities and you can
then just drop a frame (or a bunch of them) onto any form as you like.
If you do this then you don't really need form inheritance although you can
still do that - the techniques can be combined.
--
Wayne Niddery - Logic Fundamentals, Inc. (www.logicfundamentals.com)
RADBooks: http://www.logicfundamentals.com/RADBooks.html
"True peace is not the absence of tension, but the presence of
justice." - Martin Luther King, Jr.
|
|
| Back to top |
|
 |
Corinna Guest
|
Posted: Wed Sep 14, 2005 4:12 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
I think I'll try that and see what I get. Thank you all for the ideas.
-Corinna
"Wayne Niddery [TeamB]" <wniddery (AT) chaffaci (DOT) on.ca> wrote
| Quote: | Use Frames, not panels. Frames give you the design capabilities and you
can
then just drop a frame (or a bunch of them) onto any form as you like.
|
|
|
| Back to top |
|
 |
Trevor de Koekkoek Guest
|
Posted: Wed Sep 14, 2005 5:24 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
For basic visual items, such as "I want all my dialogs to have a purple
Cancel button", I would suggest Forms inheritance. It is simpler to
implement and gives very good results. For more complicated forms where the
number of things that are likely to change increases, then I think
composition is a good way to go. As is usual in design, there are
trade-offs.
-Trevor
"Corinna" <schultz (AT) harlingen (DOT) isd.tenet.edu> wrote
| Quote: | I think I'll try that and see what I get. Thank you all for the ideas.
-Corinna
"Wayne Niddery [TeamB]" <wniddery (AT) chaffaci (DOT) on.ca> wrote in message
news:43284314$1 (AT) newsgroups (DOT) borland.com...
Use Frames, not panels. Frames give you the design capabilities and you
can
then just drop a frame (or a bunch of them) onto any form as you like.
|
|
|
| Back to top |
|
 |
Charles McAllister Guest
|
Posted: Fri Sep 16, 2005 3:21 pm Post subject: Re: newbie question: Inheriting from a form? |
|
|
I just want to warn you guys about a potential bug that can crop up because of form inheritance.
i've run into this more than once....
if you have a popup menu, (or even a main menu), on the ancestor form, and you've added some items
to that menu, you'll probaly put menu breaks in there to organize the menu better. Delphi will name
these break items, N1, N2 etc.
since these names that are automatically assigned are so generic, you may have ancestor forms with
break items too with the same name. this can cause an error "component named %s already exists"
anyway just a warning. HTH.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|