In Delphi 7, I'm using a TCheckListBox. I want it to use a TStringList rather than a TStrings, so I can set Duplicates to dupIgnore, and Sorted to TRUE.
Can I just do this:
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;
Is this safe? Any caveats or suggestions?
EDIT: Removed declaration for MyStringList and added .Items to the last two assignment lines.
EDIT 2: Trying to compile the above, it looks like I'd have to cast the two final lines like this:
TStringList(CheckListBox1.Items).Sorted := TRUE;
TStringList(CheckListBox1.Items).Duplicates := dupIgnore;
Although I might be able to get this to run, I'm asking the question because just getting it to run doesn't mean it will always run or is safe.
MyStringList
? – Andreas Rejbrand Dec 11 '11 at 16:58TStrings
created byTCheckListBox
are actually of type"TListBoxStrings"
which overrides Put, Get etc methods. theSorted
property works fine without the use of TStringList. – kobik Dec 11 '11 at 17:14TListBoxStrings
? As I know,TCheckListBox.Items
is declared asTStrings
– TLama Dec 11 '11 at 17:17FItems := TListBoxStrings.Create;
inconstructor TCustomListBox.Create(AOwner: TComponent);
– kobik Dec 11 '11 at 17:18