Examples Delphi

USE A TLISTVIEW'S TLISTITEM data PROPERTY...
first a procedure to put data IN to the data field
(you can ignore most of the code below that is
not directly relevant, obviously)
/////////////////////////////////////////////////////
procedure TStepPropertiesForm.PutContainerDataOnForm;
var
objContainer: Container;
containersNum: Integer;
containerName: String;
containerDescription: String;
tempString: String;
containerID: Integer;
ListItem: TListItem;
begin
try
objContainer := CoContainer.Create;
if (containersRecSet.RecordCount > 0) then
begin
containersNum := containersRecSet.RecordCount;
containersRecSet.MoveFirst;
//get rid of anything that's already in the ListBox
ContainersListView.Items.Clear;
while not(containersRecSet.EOF) do
begin
containerID := containersRecSet.Fields['ContainerID'].Value;
containerName := objContainer.GetName(containerID);
with ContainersListView do
begin
ListItem := Items.Add;
ListItem.Caption := containerName;
ListItem.ImageIndex := 0;
ListItem.Data := TObject(containerID);
end;
containersRecSet.MoveNext;
end;
end;
except
tempString := 'The program is having problems communicating across the network';
Application.MessageBox(PChar(tempString), ' Internal Error', mb_OK);
end;
objContainer := nil;
end;
and next a procedure that gets data out of the same place:
//////////////////////////////////////////////////////////////////////
procedure TStepPropertiesForm.ContainersListViewClick(Sender: TObject);
//if the user selects an item in the ContainersListView, then show
//another ListView to the right of it, where this 'EntitiesListView'
//will show wee bitmaps of all of the entities that have been dropped
//into that container so far. If there are no dropped entities for the
//container, then show an empty EntitiesListView. Note that in order to
//show the entity images in the EntitiesListView, we need to populate
//a (new) ImageList that we can then tell the EntitiesListView to use...
var
itemNumber: Integer;
//tempString: String;
tempListItem: TListItem;
containerName: String;
containerID: Integer;
tempString: String;
begin
if (ContainersListView.SelCount > 0) then
begin
tempListItem := ContainersListView.Selected;
itemNumber := tempListItem.Index;
containerName := ContainersListView.Items[itemNumber].Caption;
containerID := Integer(ContainersListView.Items[itemNumber].Data);
tempString := 'containerID is: ' + IntToStr(containerID);
//tempString := containerName;
ShowMessage(tempString);
//DEBUGGING...
//tempString := ;
//Application.MessageBox(PChar(tempString), ' Programmers Debug Window', mb_OK);
end;
end;