Re: Default names for dynamically created objects



"Stephan Petersen" <cyber.mail5106.10.spasp@xxxxxxxx> wrote in message
news:emar2p$oem$1@xxxxxxxxxxxxxxxxxxxxxxxxxxxx

[...] The thing is that editing a component's Name property in the OI
sets the name of the instance (i.e. names the variable at the same
time). When you do it dynamically, you need to always perform two
separate steps, right?

MyOwnButton := TMyOwnButton.create;
MyOwnButton.Name = 'MyOwnButton';

Yes. But if you're creating a component at runtime, there's not in
general going to be a variable to name. Note that you are naming the
object after the variable there, not the other way around. And while
you usually save the reference to the created object somewhere, it's
often a list of created objects; something that distinguishes them
by index rather than name.

If there isn't a list but a single reference, that often doesn't make
things better, either. If you create a nested object and refer to it
from a (named) field in a wrapper object, that fields will be named
the same in _all_ wrapper objects (assuming they're all the same class
for simplicity); classtypes simply work that way. So that variable name
is useless for your purposes again. You can solve that once again by
qualifying the name with the name of the wrapper object
('wrappername.fieldname') but there is no need to store that name - it
can be generated at will whenever needed.

Groetjes,
Maarten Wiltink


.