Question

I want to get all items and subitems in my listview,but all I get is "TlistItem"

Here's my code:

procedure TFrameAnalyzer.AddEntry(opcode:word;data:Array of byte;direction:byte);
begin
  MessageBox(0,PChar(sListView1.Items.Item[4].ToString),'',0);
end;

How do I get the name of the item as string and the name of it's 2 subitems?

Was it helpful?

Solution

You can't get the name of the item, because it has no name. It has a Caption though, and a SubItems property of type TStrings. All of this can easily be found in the Delphi documentation BTW. Look into TListItem and TListItems classes.

So you could do something like

procedure TFrameAnalyzer.AddEntry(opcode:word;data:Array of byte;direction:byte);
var
  Item: TListItem;
  s: string;
begin
  Item := sListView1.Items.Item[4];
  s := Item.Caption + #13#10
    + '  ' + Item.SubItems[0] + #13#10
    + '  ' + Item.SubItems[1];
  MessageBox(0, PChar(s), nil, 0);
end;

All error handling omitted, you should certainly not access array properties in this way without checking first that the indices are valid.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top