Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Easy, I think!

Posted on 1998-03-23
1
Medium Priority
?
154 Views
Last Modified: 2011-09-20
Hi,
     I want to take info from the user into a TStringList. Firstly, there is no component associated with the stringlist, so do I declare it in the  unit's type declaration, or as a variable?
    The info is taken from an edit box. So I tried writing this:

var
   mylist : TStringList;
begin
   mylist.Add(edit1.Text);
end;

When I run this, it compiles OK, but when I try to use it, it says 'EGPFault'. Do I have to instantiate the TStringList anywhere?
Cheers, Nik

0
Comment
Question by:NikWhit
[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
1 Comment
 
LVL 4

Accepted Solution

by:
d003303 earned 40 total points
ID: 1360735
Right, you must create an object before you use it and free it afterwards. So your code should read

var
   mylist : TStringList;
begin
   myList := TStringList.Create
   mylist.Add(edit1.Text);
   // whatever code...

  myList.Free;
end;

If you want to use myList globally, put it into your forms private variables and create it in OnCreate and free it in OnDestroy.

Slash/d003303
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

647 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