[fpc-devel] Propose: change TComponent.Tag from longint to PtrInt
Michael Van Canneyt
michael at freepascal.org
Wed Sep 6 11:05:51 CEST 2006
On Wed, 6 Sep 2006, Ale Katona wrote:
> The problem here is that if you introduce a changing type to Tag, you're
> going to break streaming of the components between various platforms.
> However I think simplest would be to simply make the tag something huge
> for years to come, like Int64.
>
> The idea with hidden union is nice tho. But you'll need to know how to
> stream it precisely and there's also endianness to take care of then.
I've been following the discussion, and the tag property will remain what
it is: a 32-bit integer. It was introduced by Delphi to mimic the Tag
property which exists in VB, to allow it to be used in case statements.
Changing it will probably cause more problems than it will solve.
In casu:
Typecasting 'Tag' to a pointer is a non-portable, ugly hack and we should
not encourage such hacks.
If you want to store objects, use a TCollection, and store
TCollectionItem.ID in the component tag. ID is a unique identifier,
even when elements are added and removed from the collection.
Slightly more work, but clean and portable.
Michael.
More information about the fpc-devel
mailing list