I'm having a little trouble with adding / iterating through TLists...
Help with Linked Lists
Miscellaneous Forums/Win32 Discussion/Help with Linked Lists Here's the meat of it. I'd like to create a global TList of skill_def objects (or pointers to them, rather). I do so like this:
global skill_def_list:TList = CreateList()
And then I'd like to add my loaded skill_def objects to this list, as such:
s:skill_def = new skill_def
ListAddLast skill_def_list, s
And then I'd like to iterate through the list of objects, and reference fields, as such:
for s:skill_def = EachIn skill_def_list
print s.id
next
However, I receive the error "Identifier type does not match declared type", pointing to the "for..EachIn" line, when I try to compile/run. What am I doing wrong?
global skill_def_list:TList = CreateList()
And then I'd like to add my loaded skill_def objects to this list, as such:
s:skill_def = new skill_def
ListAddLast skill_def_list, s
And then I'd like to iterate through the list of objects, and reference fields, as such:
for s:skill_def = EachIn skill_def_list
print s.id
next
However, I receive the error "Identifier type does not match declared type", pointing to the "for..EachIn" line, when I try to compile/run. What am I doing wrong?
I will assume you already set up a type skill_def containing a field named id.
You need to change s=new skill_def to s:skill_def = new skill_def
You need to change s=new skill_def to s:skill_def = new skill_def
Sorry, edited to reflect that. It is as such in the code, the error occurs on the EachIn line.
Type skill_def
Field id:Int = 0
End Type
Add that code above your s:skill_def=New skill_def
Field id:Int = 0
End Type
Add that code above your s:skill_def=New skill_def
strict type skill_def field id=0 end type global skill_def_list:TList = CreateList() ' add a skill_def... local s1:skill_def = new skill_def ListAddLast skill_def_list, s1 ' iterate... for local s2:skill_def = EachIn skill_def_list print s2.id next
note that you have to declare "local s2:skill_def" in the loop if you have strict on just as you've declared s1 before.