我正在 Lazarus 上开发一个电子书管理器,但我在使用一个我从未使用过的组件 (TListBox
) 时遇到了一些麻烦。在名为 CategoryList
的 TListBox
上,我有这些项目:
Literature and Fiction
Romance
Computers and Internet
Poetry
Professional and Technical
Science Fiction and Fantasy
Biographies and Memoirs
Business and Finance
Children's Books
Entertainment
History
Science
Self-Help
Textbooks and Educational Materials
Travel
Westerns
当用户在 CategoryList
上选择一个项目时,我想将它存储在一个变量中,但是我该怎么做呢?
最佳答案
如果你想要索引:
index := CategoryList.ItemIndex;
如果你想要字符串:
str := CategoryList.Items[CategoryList.ItemIndex];
要捕捉用户选择某物的瞬间,您需要注册一个 OnChange 事件:
CategoryList.OnChange := CategoryListChange;
其中 CategoryListChange 是一个事件监听器:
procedure TMyForm.CategoryListChange(Sender: TObject);
begin
// do something with CategoryList.Items[CategoryList.ItemIndex]
end;
您可能想查看 this webpage 上的一些帖子也是!
关于delphi - 将 TListBox 选定行的内容存储在变量上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1972607/