Board index » cppbuilder » stornig something in TListItem->Data

stornig something in TListItem->Data


2004-04-04 11:57:43 PM
cppbuilder62
I have an integer value a; I need to store it in the list item and extract
when required.
How do I do it?
I tried out numerous ways of assinging this int to void*, with wierdest
pointer operations, and yet when I need to extract the value I get weird
results.
What is the right way to stuff a value in there and to get it out
afterwards?
 
 

Re:stornig something in TListItem->Data

TListView* listView = new TListView(this);
listView->Parent = this;
listView->Top = 100;
listView->Left = 100;
TListItem* listItem;
listItem = listView->Items->Add();
listItem->Data = (void*)1;
listItem->Caption = "One";
listItem = listView->Items->Add();
listItem->Data = (void*)2;
listItem->Caption = "Two";
listItem = listView->Items->Add();
listItem->Data = (void*)3;
listItem->Caption = "Three";
for(int i = 0; i < 3; i++)
{
listItem = listView->Items->Item[i];
int data;
data = (int)(listItem->Data);
ShowMessage(listItem->Caption + " : " + data);
}
Be carefull if your storing pointers in the TListItem->Data. For primitive
types you have nothing to worry about.