我尝试为每个选定的listitem做一个操作,但它不会工作。 这是我的尝试:为每个选定的listitem
var
TLsttem:TListItem;
begin
for TLsttem in form1.listview1.Selected do
begin
...
end;
end;
现在我得到这个错误:
[dcc32 Error] MSGBox.pas(50): E2431 for-in statement cannot operate on collection type 'TListItem' because 'TListItem' does not contain a member for 'GetEnumerator', or it is inaccessible
我怎样才能解决这个问题?
编辑: 我现在尝试这个脚本:
TLsttem := form1.ListView1.Selected;
while TLsttem <> nil do
begin
showmessage('Test');
TLsttem := form1.ListView1.GetNextItem(TLsttem, sdAll, [isSelected]);
end;
但我只拿到1个消息,我怎么能解决这个问题?
你不能遍历一个单一项目('Selected'属性返回当前选中TListItem),而不是必须用'Items'属性它返回一个集合。 – RRUZ
你为什么使用'form1'全局变量?我敢打赌,代码在'TForm1'的方法中运行。 –