Right now I am using the following code to get a ListView items value and I was wanting to know if this was the proper way to do this or should I be doing it another way.
Example for the parent item value:
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(ListView1.Selected.Caption);
end;
Example for a sub item value:
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(ListView1.Selected.SubItems.Strings[items_index_here]);
end;
Your first code seems fine, except you should be checking to see if there is a
Selecteditem first:Your second can be simplified (and should include the same check I mentioned above):
TStringsdescendants (likeTStringListandTListItem.SubItems) have default properties, which is a shortcut to usingTStrings.Strings[Index]; you can instead just useTStrings[Index]. Instead ofMyStringList.Strings[0], you can just useMyStringList[0], and this applies to things likeTMemo.LinesandTListItem.SubItemsas well. You don’t needSubItems.Strings[Index], but can just useSubItems[Index].