Board index » delphi » Possible to have Const TCollectionItem

Possible to have Const TCollectionItem

Has anyone set a TCollectionItem as a constant Value in the Const
section of code.  I have been wondering if this is possible with any
object really.  Could someone post some code as an example if this has
been done.

Thanks

 

Re:Possible to have Const TCollectionItem


In article <1e77f51d.0106120522.1b447...@posting.google.com>,

Quote
firewolf2...@hotmail.com (Johnny) writes:
>Has anyone set a TCollectionItem as a constant Value in the Const
>section of code.  I have been wondering if this is possible with any
>object really.  Could someone post some code as an example if this has
>been done.

You'll have to explain a bit more what you mean, normally they are instances of
the same class with different data (property) settings. If all the objects are
identical in _all_ respects, why not just have a reference count.

Alan Lloyd
alangll...@aol.com

Re:Possible to have Const TCollectionItem


Quote
alangll...@aol.com (AlanGLLoyd) wrote in message <news:20010613011503.00947.00002386@nso-fs.aol.com>...
> In article <1e77f51d.0106120522.1b447...@posting.google.com>,
> firewolf2...@hotmail.com (Johnny) writes:

> >Has anyone set a TCollectionItem as a constant Value in the Const
> >section of code.  I have been wondering if this is possible with any
> >object really.  Could someone post some code as an example if this has
> >been done.

> You'll have to explain a bit more what you mean, normally they are instances of
> the same class with different data (property) settings. If all the objects are
> identical in _all_ respects, why not just have a reference count.

> Alan Lloyd
> alangll...@aol.com

I made a created a child collection object, however in my code I will
be useing certain predefined settings in it.  But I still want to
leave the ability to add to it later.  I really would like to set the
constant values in constant 'interface' of code.

The only way I have seen to do this so far is to use a record as the
hidden elements of the TCollectionItem and make it kinda nonapparent
uesing record.field in the read and write declarations.  I can then
use a record constant to have my constant data in the interface
section.  This is however non-optimal.  I would rather be able to have
constant values of the object.

Any ideas?

Thanks

Re:Possible to have Const TCollectionItem


In article <1e77f51d.0106130521.39937...@posting.google.com>,

Quote
firewolf2...@hotmail.com (Johnny) writes:
>I made a created a child collection object, however in my code I will
>be useing certain predefined settings in it.  But I still want to
>leave the ability to add to it later.  I really would like to set the
>constant values in constant 'interface' of code.

>The only way I have seen to do this so far is to use a record as the
>hidden elements of the TCollectionItem and make it kinda nonapparent
>uesing record.field in the read and write declarations.  I can then
>use a record constant to have my constant data in the interface
>section.  This is however non-optimal.  I would rather be able to have
>constant values of the object.

I not _quite_ sure what you want but the following fits some of the
possibilities <g>

1 Different values for a standard set of named constants

a)  Make a different constructor In the TCollection descendant with additional
parameters which are stored in private variables (it would have to have a
different name from "Create"). The TCollectionItem descendant accesses these
variables in its create constructor to set it's constants.

b) Make the constants properties of the TCollection descendant which you set
before adding any TCollectionItems to the collection.

2 Different set of named constants

a) Make a descendant of the TCollection in which you set the variables in your
code as additional to the base class. Make a descendant of the TCollectionItem
which uses those constants in addition to the base class.

As the set is of constants (ie does not change between collection items) then
they should be held by the collection, and accessed for each new collection
item.

If the set of constants does not change, then all you need is some mechanism to
set the changed values into the collection - ie ini-file, or properties or
create parameters.

If the contents of the set of constants changes, then both the collection and
collection items have to change to cater for the differences - ie you're into
descendants.

Alan Lloyd
alangll...@aol.com

Re:Possible to have Const TCollectionItem


Quote
alangll...@aol.com (AlanGLLoyd) wrote in message <news:20010613154601.04183.00000226@nso-fq.aol.com>...
> In article <1e77f51d.0106130521.39937...@posting.google.com>,
> firewolf2...@hotmail.com (Johnny) writes:

> >I made a created a child collection object, however in my code I will
> >be useing certain predefined settings in it.  But I still want to
> >leave the ability to add to it later.  I really would like to set the
> >constant values in constant 'interface' of code.

> >The only way I have seen to do this so far is to use a record as the
> >hidden elements of the TCollectionItem and make it kinda nonapparent
> >uesing record.field in the read and write declarations.  I can then
> >use a record constant to have my constant data in the interface
> >section.  This is however non-optimal.  I would rather be able to have
> >constant values of the object.

> I not _quite_ sure what you want but the following fits some of the
> possibilities <g>

> 1 Different values for a standard set of named constants

> a)  Make a different constructor In the TCollection descendant with additional
> parameters which are stored in private variables (it would have to have a
> different name from "Create"). The TCollectionItem descendant accesses these
> variables in its create constructor to set it's constants.

> b) Make the constants properties of the TCollection descendant which you set
> before adding any TCollectionItems to the collection.

> 2 Different set of named constants

> a) Make a descendant of the TCollection in which you set the variables in your
> code as additional to the base class. Make a descendant of the TCollectionItem
> which uses those constants in addition to the base class.

> As the set is of constants (ie does not change between collection items) then
> they should be held by the collection, and accessed for each new collection
> item.

> If the set of constants does not change, then all you need is some mechanism to
> set the changed values into the collection - ie ini-file, or properties or
> create parameters.

> If the contents of the set of constants changes, then both the collection and
> collection items have to change to cater for the differences - ie you're into
> descendants.

> Alan Lloyd
> alangll...@aol.com

Basicly a object that there are several values (for the variables).
These values will be constant.  However I was looking for a way to
pack the values in at the interface constant level and not have to
further assign them variable by variable in code.  ie. (in psuedocode)

TComputer = class(TCollection)
end;

TCompComponent = class(TCollectionItem)
  ComponentType : string; {ct}
  ComponentVale : string; {cv}
end;

examples of constant values would be (ct = Processor, cv = 486/66) (ct
= Processor, cv = Pentium 133) (ct = CDRom, cv = 32X) (ct = Memory, cv
= 16MB_Async_70NS)

as these are by FAR not the only values possible I can not lock this
into a structure that is not flexible.  I would like to have the
benefits of TCollection as well in this component(ie self aware
freeing, etc..).  Trying to set all of this in a section of code is
certainly a possibility, but due to the overwheleming number of items
to be added to the TComponentType set, I would really rather define it
in a place and just 'assign' the whole set of values later.

(This is just a simple example of the much more variable rich
TCollectionItem I am truely useing)

Other Threads