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
Check out the RegisterClass procedure in the help.
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.
>
> 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?
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...
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 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.