Forum > Beginners
How to construct a list of integers with TList functionality?
py2pa:
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: ---my_list: TList;
--- End code ---
and then give something like this:
--- Code: ---my_list.Add(1);
--- End code ---
the compiler throws the error "pointer expected". Please help.
MichaelBM:
You need to create the list before using the method Add().
my_list.Create;
my_list.Add('1');
py2pa:
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:
Afaik unit fgl contains a generic version of Tlist, TList<>
Leledumbo:
--- Quote from: py2pa on August 17, 2014, 02:10:01 pm ---the compiler throws the error "pointer expected". Please help.
--- End quote ---
TList is a list of pointer. Specialize TFPGList with integer and use that instead.
--- Quote from: MichaelBM on August 17, 2014, 02:14:06 pm ---You need to create the list before using the method Add().
my_list.Create;
my_list.Add('1');
--- End quote ---
2 mistakes:
* constructor result is assigned to the variable that will hold it, not called with the variable itself
* with TList, it will still generate "pointer expected" error
Navigation
[0] Message Index
[#] Next page