Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 383
  • Last Modified:

abstract classes

i would to use a TStrings obect to store some strings, but it always generate an abstract error, because TStrings is an abstract class. could anyone tell me how to proceed?

regards
                  Ralph

ps:i would use lots of tstrings ogjects so i can't use a listbox or another else.
0
ralph78
Asked:
ralph78
  • 4
  • 3
1 Solution
 
MotazCommented:
use TStringList to create TStrings instances such as:

var
  S: TStrings;
begin
  S:= TStringList.Create;
....

Motaz
0
 
RLancasterCommented:
An abstract class is one you would use as a base class for creating your own classes.

e.g.

TMyStringsClass = class(TStrings)
  ..
  ..
end;

This works much in the same was as TStringList which is a descendant class of TStrings. Motaz's comment is not quite correct. It may work programmatically but is not theoretically correct. If you just want to store a bunch of strings and process them use TStringList instead. Or you can now extend the base class to add your own required functionality.

Isn't Object Oriented Programming wonderful !!! :)
0
 
MotazCommented:
So what is the difference between TStrings and TStringList in functionality?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
RLancasterCommented:
From the Help:

TStrings is the base class for objects that represent a list of strings.

Unit

classes

Description

Derive a class from TStrings to store and manipulate a list of strings. Descendants of TStrings can represent several individual strings, such as the individual lines that appear in a list box. Some objects use descendants of TStrings to represent one long body of text so that it can be manipulated in smaller chunks.

TStrings introduces many properties and methods to

Add or delete strings at specified positions in the list.
      Rearrange the strings in the list.
      Access the string at a particular location.
      Read the strings from or write the strings to a file or stream.
      Associate an object with each string in the list.

TStringList maintains a list of strings.

Unit

classes

Description

Use a string list object to store and manipulate a list of strings. TStringList implements the abstract properties and methods introduced by TStrings, and introduces new properties, events, and methods to

Sort the strings in the list.
      Prohibit duplicate strings in sorted lists.
      Respond to changes in the contents of the list.

Does that answer your question Motaz ?

:)
0
 
MotazCommented:
did you mean that I can use TStrings to store my own data type, or must I derive it to my own class. I inherit TList to define my own class to manipulate to my own data type such as records, but this method takes long time to override many methods such as Get, Put, Delete, ,,,

Motaz
0
 
RLancasterCommented:
No, TStrings is a base class for string containers. To store your own data type derive a calss from TList (which can store anything anyway)
0
 
MotazCommented:
Ok, thanks
0
 
ralph78Author Commented:
thanks you both!
Ralph
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now