Delphi 以 TStrings 統一封裝各類字串列表(ComboBox、ListBox、Memo.Lines、Font 列表、Notebook 頁籤、StringGrid 等),提供一致操作介面,支援跨控制項複製轉換。
Count(唯讀,索引 0 起算,最大索引 = Count-1)Strings[Index] 或直接 [Index](Strings 為預設屬性)IndexOf('字串') 回傳位置,找不到為 -1,僅支援完整比對Add('尾端')、Insert(Index, '中間')Move(CurrIndex, NewIndex)(連帶物件同步)Delete(Index)、Clear(全清)目標 := 來源(覆寫)、AddStrings(來源)(附加)for i := 0 to List.Count-1 do ...if FileListBox1.Items.IndexOf('AUTOEXEC.BAT') > -1 then
begin
Color := clYellow;
Label1.Caption := 'You are in the root directory!';
end;
with ListBox1.Items do
if IndexOf('bureaucracy') > -1 then
Delete(IndexOf('bureaucracy'));
for I := 0 to ListBox1.Items.Count - 1 do
ListBox1.Items[I] := UpperCase(ListBox1.Items[I]);
Object Inspector 中雙擊 TStrings 屬性彈出字串列表編輯器,可視化增刪改項目。