In the help file, when they want to use a list of string, they declare
the variable as TStrings and create it with the TStringList constructor.
Why ? Couldn't they declare it as TStringList ?
Wich of those we are suppose to use. Any help, specially from Delphi
technical support, would be greatly appreciated.
Richard.
Richard:
I think this is a mistake in the help file. Elsewhere, it says:
"String objects are used by various components to manipulate
strings. A string object has no way to store a string, but
instead uses the native storage ability of the control that uses
it.
"For example, the Items property of a list box control is of type
TStrings. The strings that appear in a list box control are stored
in a list box string object (TListBoxStrings), which is
derived from TStrings. When you add or delete items in a list box,
you are adding and deleting them from a list box string object.
"To maintain a list of strings outside of a control, use a string
list object (TStringList)."
I haven't had any problems working along these lines.
--
Best wishes
John Nurick
e-mail: j.nu...@dial.pipex.com
v-mail: <+44|0> 191 281 1306
>I want to know what is the difference between TStrings and TStringList
>objects.
>
>In the help file, when they want to use a list of string, they declare
>the variable as TStrings and create it with the TStringList constructor.
> Why ? Couldn't they declare it as TStringList ?
TStrings is an abstract class, meaning you cannot create and use an
instance of the class, but must use a derived class, such as
TStringList.
Each of the classes that derive from TStrings has a different
implementation. Each class stores the strings differently. Using
TStrings as a property value lets Borland hide the implementation
class. Thus, you don't need to know about TListBoxStrings,
TMemoStrings, and so on. Instead, you can use the abstract interface
of TStrings.
Using TStrings as a paramter type allows a routine to use any class
that inherits from TStrings. Thus, it is easy to copy all the strings
out of a list box and into a memo (Memo1.Lines := ListBox1.Items).
When you create your own components, you must use TStringList to
create a string list object (or use another class that inherits from
TStrings). You can choose to declare a property of type TStrings or
TStringList. By using TStrings, you are free to change the
implementation without changing the interface.
--
Ray Lischner li...@tempest-sw.com
Tempest Software, Corvallis, Oregon, USA http://www.tempest-sw.com