Why does Memo.Lines use the abstract class TStrings? Why doesn’t it use TStringList instead?
And should I convert it to TStringList before working with it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
TMemo.Lines,TListBox.Items,TComboBox.Items, etc. ; all are declared asTStrings. Beware, talking about the property that is! The internal created types areTMemoStrings,TListBoxStringsandTComboBoxStringsrespectively, which are all descendants ofTStringsand differ all in way of storage.And why? For interchangeability and interoperability. So every
TStrings-descendant has the same properties, and so you can do:How to use? Well, a
TStringsproperty likeTMemo.Linesworks just fine. You can add, delete, change, renew and clear the strings (and objects) on the property, because internally it is aTMemoStringswhich implements all this interaction. Declaration <> implementation.But when you want any special handling, e.g. like sorting which
TStringListprovides, then you need help. You cannot typecast nor convert aTMemo.Linesto aTStringList, because it isn’t one, but instead you need to create an intermediate object for this special processing: