Doing what Ulfeng proposes won't work. TListBox's Items property has this line in its Set method:
Items.Assign(Value);
so assigning SL to AListBox.Items only copies the string inside SL to the string holder of AList. The only way to do what you ask would be inheriting from TListBox and overriding the Items property with one of your own. Something like this:
constructor TSLListBox.Create(aOwner: TComponent);
begin
inherited;
FSLItems:= TStringList.Create;
FSLItems.OnChange:= SLChange;
end;
destructor TSLListBox.Destroy;
begin
FSLItems.Free;
inherited;
end;
procedure TSLListBox.SetSLItems(const Value: TStringList);
begin
FSLItems.Assign(Value);
end;
procedure TSLListBox.SLChange(aSender: TObject);
begin
// This line updates the original string repository with the changes made to SL
TListBox(Self).Items:= FSLItems;
end;
This approach has several disadvantages. First this is not a visual component nor a example of clean and nice inheritance. The second and more insidious problem is that properties are statically linked, meaning that if you pass a reference of your new ListBox to a procedure that expects a TListBox, the code inside the procedure will access the Items of TListBox and not those you declared. Any items added or deleted won't be reflected on FSLItems and your object will be inconsistent.
I'm not sure why you want to do this kind of modification, as almost everything available in a TStringList is also available in the TListBox. Maybe if you clarify a little more the pourpose of the mod, we can think of an alternative way of doing it.
Well because the stringlist has a duplicates property,and tsrtings does not. but I did get around this by using the first example above.
when i add to the listbox i first add to a globall stringlist. then i clear the list box and copy the stringlist to the listbox. works fine for what i need.
later when i learn more i will attempt to create a custom listbox with a duplicates property.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.