The Tag property exposed by many Windows Common Controls (including TreeView's Node objects and ListView's ListItem objects) is more versatile than the ListBox and ComboBox controls' ItemData property, because it is of Variant type and can therefore accept values of most data types.
However, it can't be used to store an object reference, probably because of an implementation bug. If you want to associate an item to an object you can use the Tag property as an index into an object array, but fortunately there is a simpler and more efficient method.
When you want to store an object reference into a Tag property, assign it the pointer to the object (a Long value): |
When you later need to rebuild the object reference, you use the CopyMemory API function to manually store the object pointer into a suitable object variable: |
You can use the same technique with the ItemData property of ListBox and ComboBox controls. It is mandatory, however, that the object be referenced by at least another object variable, because the weak reference held in the Tag property doesn't keep it alive. If the object is destroyed and you later try to access it in the way described above, you get a runtime error or - worse - a GPF error.
|
|