### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: How to construct a list of integers with TList functionality?  (Read 7374 times)

#### py2pa

• New Member
• Posts: 11
##### How to construct a list of integers with TList functionality?
« on: August 17, 2014, 02:10:01 pm »
I want to construct a list of integers, but not as an simple array. I want my list to have the full functionality that TLists provide (inserting and moving elements etc). How can I do that? Because, if I declare my list as:

Code: [Select]
`my_list: TList;`
and then give something like this:

Code: [Select]
`my_list.Add(1);`

#### MichaelBM

• New Member
• Posts: 38
##### Re: How to construct a list of integers with TList functionality?
« Reply #1 on: August 17, 2014, 02:14:06 pm »
You need to create the list before using the method Add().

my_list.Create;
"Everything must be made as simple as possible. But not simpler.”

#### py2pa

• New Member
• Posts: 11
##### Re: How to construct a list of integers with TList functionality?
« Reply #2 on: August 17, 2014, 02:18:07 pm »
I have created it, just ommitted the line. Also, if I pass the number as a string to Add method ('1'), I get the same error ("expected Pointer').

#### marcov

• Hero Member
• Posts: 11654
• FPC developer.
##### Re: How to construct a list of integers with TList functionality?
« Reply #3 on: August 17, 2014, 02:32:00 pm »
Afaik unit fgl contains a generic version of Tlist, TList<>

#### Leledumbo

• Hero Member
• Posts: 8766
• Programming + Glam Metal + Tae Kwon Do = Me
##### Re: How to construct a list of integers with TList functionality?
« Reply #4 on: August 17, 2014, 03:16:20 pm »
TList is a list of pointer. Specialize TFPGList with integer and use that instead.
You need to create the list before using the method Add().

my_list.Create;