Solved

abstract classes

Posted on 2000-04-17
8
380 Views
Last Modified: 2013-11-23
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
Comment
Question by:ralph78
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 7

Expert Comment

by:Motaz
ID: 2722395
use TStringList to create TStrings instances such as:

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

Motaz
0
 
LVL 1

Accepted Solution

by:
RLancaster earned 50 total points
ID: 2723276
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
 
LVL 7

Expert Comment

by:Motaz
ID: 2725522
So what is the difference between TStrings and TStringList in functionality?
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 1

Expert Comment

by:RLancaster
ID: 2725537
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
 
LVL 7

Expert Comment

by:Motaz
ID: 2725583
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
 
LVL 1

Expert Comment

by:RLancaster
ID: 2725680
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
 
LVL 7

Expert Comment

by:Motaz
ID: 2725694
Ok, thanks
0
 

Author Comment

by:ralph78
ID: 2726945
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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 6 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question