在Delphi 7中,我使用的是TCheckListBox。 我希望它使用TStringList而不是TStrings,因此我可以将Duplicates设置为dupIgnore,并将Sorted设置为TRUE。
我可以这样做:
Form1 = class(TObject
CheckListBox1: TCheckListBox; // created by the IDE
end;
procedure TForm1.FormCreate
begin
CheckListBox1.Items.Free;
CheckListBox1.Items := TStringList.Create;
CheckListBox1.Items.Sorted := TRUE;
CheckListBox1.Items.Duplicates := dupIgnore;
end;
这样安全吗? 有任何警告或建议吗?
编辑:删除了MyStringList的声明,并将.Items添加到最后两个赋值行。
编辑2:尝试编译上面的内容,看起来我必须像这样抛出最后两行:
TStringList(CheckListBox1.Items).Sorted := TRUE;
TStringList(CheckListBox1.Items).Duplicates := dupIgnore;
虽然我可能能够让它运行,但我问这个问题,因为只是让它运行并不意味着它总会运行或安全。