?
Solved

Easy, I think!

Posted on 1998-03-23
1
Medium Priority
?
153 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

764 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