views:

502

answers:

1

Hello,

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?

+5  A: 

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.

mghie
Could make more readable (IMHO) by removing parentheses and comma separators, preceding items with "+ #13 +" and subitems with "+ ' '#13 +"
Argalatyr
Yes, thanks for the comment. I just wanted to make them stand out properly, not lump them into one code line.
mghie
Thank you,it works.
John
I have one question,why the tag "Winforms" wouldn't be appropriate if I'm using Delphi 2009? Isn't the VCL in delphi winforms?
John
The "standard" VCL (not VCL.net) is a native code wrapper for the Windows API. Windows Forms is a managed code (.NET) wrapper for the Windows API. In fact, .NET was inspired by the VCL, having the same person involved in the creation of both. Wikipedia has the gist of it under "winforms" and "VCL". Delphi 2009 has nothing whatsoever to do with the creation of winforms apps. I'll retag accordingly.
mghie
@mghie: I never use "#10" in this context. I know the relevance in file systems, but for display I've never needed anything other than #13. Just interesting, that's all.
Argalatyr