Board index » delphi » inserting class into inheritance-hierarchy - HELP!

inserting class into inheritance-hierarchy - HELP!

Hi!

I'm rather new to Delphi and right now I have the problem that I'd need
to insert a class into my inheritance-tree.

I've done that a coupla time in PowerBuilder quite a while ago, so
basically I know what is to be done. Only in _which_ files???

I have 30 forms that are all based on TForm.
Due to changes in the specifications, it would be _very_ convenient to
now insert

TLetterTemplate=class(TForm)
    ...

as a buffer between the report-forms and TForm. Thus

RptOne=class(TLetterTemplate)
    ...

I know I have to change the declaration in the *.pas files and the
definitions in the *.dfm files. But still I get errors when trying to
re-open the unit or switch from the form-view to code-view via F12.

Where else are references of class ancestors stored?

TIA
Andrea

 

Re:inserting class into inheritance-hierarchy - HELP!


"Andrea Wahl" <andrea.w...@dresdner-bank.com> skrev i melding
news:3ABA1A74.DFA8BAD9@dresdner-bank.com...

Quote
> Hi!

> I'm rather new to Delphi and right now I have the problem that I'd need
> to insert a class into my inheritance-tree.

> I've done that a coupla time in PowerBuilder quite a while ago, so
> basically I know what is to be done. Only in _which_ files???

> I have 30 forms that are all based on TForm.
> Due to changes in the specifications, it would be _very_ convenient to
> now insert

> TLetterTemplate=class(TForm)
>     ...

> as a buffer between the report-forms and TForm. Thus

> RptOne=class(TLetterTemplate)
>     ...

> I know I have to change the declaration in the *.pas files and the
> definitions in the *.dfm files. But still I get errors when trying to
> re-open the unit or switch from the form-view to code-view via F12.

> Where else are references of class ancestors stored?

If I were you, I'd lay off form inheritance until I learned a bit more about
Delphi / Object Pascal. The form classes are a bit special when it comes to
inheritance, I must admit my own kinowledge after 6 years of full-time Delphi
programming, I have none but negative experience with form inheritance. The
reason is, as far as I can see, that all form classes actually need a .dfm
file. The .dfm file of an "abstract" parent class is actually implemented
into the project as an empty, never-used form resource. Really confusing, and
it may be a real disaster if you need to change the parent class, AFAIK.
Better use templates, this has nothing to do with inheritance, but works like
a "macro", copying all the contents form another form as a starting point.

It may be that I just never understood the power of inheriting forms,
though...;-)
--
Bjoerge Saether
Consultant / Developer
http://www.itte.no
Asker, Norway
bjorgeremovet...@itte.no (remove the obvious)

Re:inserting class into inheritance-hierarchy - HELP!


On Thu, 22 Mar 2001 16:29:56 +0100, Andrea Wahl

Quote
<andrea.w...@dresdner-bank.com> wrote:
>I have 30 forms that are all based on TForm.
>Due to changes in the specifications, it would be _very_ convenient to
>now insert

>TLetterTemplate=class(TForm)
>    ...

>as a buffer between the report-forms and TForm. Thus

>RptOne=class(TLetterTemplate)
>    ...

OK here we go...

Once you've got your "TLetterTemplate" form created the next step is
setting the report form to inherit from the new form, as you've
written above:

Quote
>RptOne=class(TLetterTemplate)

You also need to make sure the "TLetterTemplate" unit is in the
reports uses list.

Now go to the form view and right click on your form. Select View as
Text (if this is not available you'll probably need to make sure "Text
DFM" is checked in that popup menu).

First line of the DFM will probably read something like:

object RptOne : TRptOne

Change it to be:

inherited RptOne : TRptOne

Now hit Alt+F12 or select "View as Form" from the right click menu to
return to design mode.

Your RptOne Form should now inherit from the TLetterTemplate Form and
any changes made to the TLetterTemplate will occur in all of the
reports you write that inherit from it.

Hope this Helps

Rob.

Re:inserting class into inheritance-hierarchy - HELP!


On Thu, 22 Mar 2001 19:19:35 +0100, "Bj?rge S?ther"

Quote
<REMOVE_bsaether@THIS_online.no> wrote:
>"Andrea Wahl" <andrea.w...@dresdner-bank.com> skrev i melding
>news:3ABA1A74.DFA8BAD9@dresdner-bank.com...
>> Hi!

>> I'm rather new to Delphi and right now I have the problem that I'd need
>> to insert a class into my inheritance-tree.

>> I've done that a coupla time in PowerBuilder quite a while ago, so
>> basically I know what is to be done. Only in _which_ files???

>> I have 30 forms that are all based on TForm.
>> Due to changes in the specifications, it would be _very_ convenient to
>> now insert

>> TLetterTemplate=class(TForm)
>>     ...

>> as a buffer between the report-forms and TForm. Thus

>> RptOne=class(TLetterTemplate)
>>     ...

>> I know I have to change the declaration in the *.pas files and the
>> definitions in the *.dfm files. But still I get errors when trying to
>> re-open the unit or switch from the form-view to code-view via F12.

>> Where else are references of class ancestors stored?

>If I were you, I'd lay off form inheritance until I learned a bit more about
>Delphi / Object Pascal. The form classes are a bit special when it comes to
>inheritance,

This sounds right to me. (I don't know whether it's actually true that

there's something special about those classes per se, but there's
certainly a lot that's special about the way forms are handled by
Delphi, which comes to the same thing.)

At least in D3 the way to get form inheritance is via the
"Object Repository": You can add a form to the Repository
using Project|AddToRepository, and then it appears on the
list of forms that you get from File|New; you can choose
Copy, Inherit, or Use depending on how you want to use
the saved form. There must be something similar if not
identical in D4 and D5.

- Show quoted text -

Quote
> must admit my own kinowledge after 6 years of full-time Delphi
>programming, I have none but negative experience with form inheritance. The
>reason is, as far as I can see, that all form classes actually need a .dfm
>file. The .dfm file of an "abstract" parent class is actually implemented
>into the project as an empty, never-used form resource. Really confusing, and
>it may be a real disaster if you need to change the parent class, AFAIK.
>Better use templates, this has nothing to do with inheritance, but works like
>a "macro", copying all the contents form another form as a starting point.

>It may be that I just never understood the power of inheriting forms,
>though...;-)
>--
>Bjoerge Saether
>Consultant / Developer
>http://www.itte.no
>Asker, Norway
>bjorgeremovet...@itte.no (remove the obvious)

Other Threads