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

Unnecessary components in a class

0 views
Skip to first unread message

Frank Peelo

unread,
Jan 25, 2001, 12:48:41 PM1/25/01
to
When you add a component to a form, Delphi puts an instance of that
component type in the class controlling the form. I think they are not
all necessary.

I was modifying a form with dozens and dozens of components in tabbed
pages. A lot of the items on the form were not well named, with names
like Label57 so I did an alt-F12 to edit them in text mode and gave
the ones I was working on more meaningful names. Wasn't sure if Delphi
would maintain the class, but it's under version control, the worst
that can happen is I have to go back to the start.

File|Save All. Delphi complains that a reference on the form has no
corresponding component. Fine, let Delphi delete it. Compile. Run.
Everything is fine. Do a visual compare from the version control and
Wow! The new names I put in are not there! Yet everything runs!

Most of the controls are data-aware, so there are no events defined
specifically in this form, so most of the components defined in the
form's class are never used in any Pascal code. So maybe they are not
needed. I delete all I can get away with. Now the program compiles OK
but doesn't run, some of the (3rd party) components cannot be created
at compile time. Seems there needs to be at least 1 reference to a
component of that type to force the type to be registered. Put that
many back, everything works again.

Anyway, I got rid of a load of useless class references. Presumably
Delphi reads in the form at run time, and for each component it create
an instance in some sort of a container, linked list or dynamic array
or whatever. Then if there is a reference in the form class it gets a
copy. I don't know how much overhead (bytes or elapsed runtime) this
costs, but it seems to me that there must be some waste. Would anyone
know if there is a tool for finding out which are unnecessary and
getting rid of them automagically?

FP


Bruce Roberts

unread,
Jan 25, 2001, 2:29:27 PM1/25/01
to

"Frank Peelo" <fpe...@portablesolutions.com> wrote in message
news:94pp6b$bkr$1...@kermit.esat.net...

> When you add a component to a form, Delphi puts an instance of that
> component type in the class controlling the form. I think they are not
> all necessary.

Check out the RegisterClass procedure in the help.

Frank Peelo

unread,
Jan 26, 2001, 8:36:18 AM1/26/01
to

"Bruce Roberts" <b...@bounceitattcanada.xnet> wrote in message
news:0c%b6.6803$Oe.3...@tor-nn1.netcom.ca...

ok, I'll rephrase it. "Of course they are not all necessary". Sorry,
my post was too long. You didn't need to know _how_ I found out that
the class needed an instance of the type (I'm not going to start
calling RegisterClass explicitly, that would be worse). I'll repeat
just the question then.

Bruce Roberts

unread,
Jan 26, 2001, 2:17:51 PM1/26/01
to

"Frank Peelo" <fpe...@portablesolutions.com> wrote in message
news:94rup4$pn1$1...@kermit.esat.net...

>
> I don't know how much overhead (bytes or elapsed runtime) this
> costs, but it seems to me that there must be some waste. Would anyone
> know if there is a tool for finding out which are unnecessary and
> getting rid of them automagically?

I have to admit to being confused. Is the problem that you believe that
there are classes being registered that are never used?


Henrik Palmér

unread,
Jan 26, 2001, 3:03:08 PM1/26/01
to
If I have understood you correctly, what you are doing is the same as
assigning '' to a component's name, thus preventing them from showing up
below 'Form1 = class(TForm)'. This is quite useful when a lot of components
are only for show -- such as TPanels for aligning or your data-aware
controls. I have found that you need at least one named component of every
design-time class lest not get the message 'Class not registered'.

Sorry for responding directly to your e-mail address, but I'm not sure that
my posts ever show up.

"Frank Peelo" <fpe...@portablesolutions.com> skrev i meddelandet
news:94pp6b$bkr$1...@kermit.esat.net...

Frank Peelo

unread,
Jan 29, 2001, 6:20:36 AM1/29/01
to

"Bruce Roberts" <b...@bounceitattcanada.xnet> wrote in message
news:ojkc6.7135$Oe.3...@tor-nn1.netcom.ca...

Yes. I found, by accident, that if the component is not used in the
Pascal code, it does not seem to be needed in the form class (subject
to at least one example of each component type used being declared, so
they get registered). It seems to me that named class references in
the form class would have to be individually initialised when the
class is built; that must cost something so I thought it might be good
to get rid of them.

Bruce Roberts

unread,
Jan 29, 2001, 3:59:59 PM1/29/01
to

"Frank Peelo" <fpe...@portablesolutions.com> wrote in message
news:953jun$q9h$1...@kermit.esat.net...

> >
> > I have to admit to being confused. Is the problem that you believe
> that
> > there are classes being registered that are never used?
>
> Yes. I found, by accident, that if the component is not used in the
> Pascal code, it does not seem to be needed in the form class (subject
> to at least one example of each component type used being declared, so
> they get registered). It seems to me that named class references in
> the form class would have to be individually initialised when the
> class is built; that must cost something so I thought it might be good
> to get rid of them.
>

I doubt that the time taken to initialize all the classes is really
significant. If memory serves the RegisterClass procedure is defined in
Classes.pas. Take a look at it, it really doesn't do very much. IMO, you
would find it more productive to look at other areas of optimization.


0 new messages