Solved

Easy, I think!

Posted on 1998-03-23
1
150 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
1 Comment
 
LVL 4

Accepted Solution

by:
d003303 earned 10 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

Suggested Solutions

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

680 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