Solved

abstract classes

Posted on 2000-04-17
8
374 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
  • 4
  • 3
8 Comments
 
LVL 7

Expert Comment

by:Motaz
Comment Utility
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
Comment Utility
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
Comment Utility
So what is the difference between TStrings and TStringList in functionality?
0
 
LVL 1

Expert Comment

by:RLancaster
Comment Utility
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 7

Expert Comment

by:Motaz
Comment Utility
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
Comment Utility
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
Comment Utility
Ok, thanks
0
 

Author Comment

by:ralph78
Comment Utility
thanks you both!
Ralph
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now