Page 1 of 1

ITER troubles.

Posted: 29 Jun 2019 06:15
by Ron Melby
I know you think this is old ground, sorry. I cannot figure out how to stop an unibounded (or perhaps you might think of them as set within limits) iterator. Never have worked with them on subtypes.

typical FAM record (stripped)

FAM = FAM ptr
HUSBAND = INDI ptr
WIFE = INDI ptr
CHIL = INDI ptr
CHIL = INDI ptr

ANOTHER FAM

here is the stripped code:

local ptr = fhNewItemPtr()
ptr:MoveToFirstRecord('FAM')
while ptr:IsNotNull() do
matFAM(ptr)
...

function matFAM(ptrFAM)
if ptrFAM:IsNotNull() then
...

ptrCHIL = fhGetItemPtr(ptrFAM, '~.CHIL>')
while ptrCHIL:IsNotNull() do
table.insert(tblFAM, fid)
matID(ptrCHIL)
matNAME(ptrCHIL)
matSEX(ptrCHIL)
matLifeInf(ptrCHIL)
matCEM(ptrCHIL)
ptrCHIL:MoveNext('SAME_TAG') -- NEXT Child in FAM
end

it is obvious that CHIL> is an iterator.

I need the ITEM and not LINK for matCEM and that is already a large complex function, I simplistically figure if its an ITEM it is an indi ptr if a link a sour ptr. (although the deciding just between link and item is no small deal.)

of course this will read all CHIL in any fam at present.how can I set limits to this.FAM? Husband and wife work well because they are not in a loop.

Re: ITER troubles.

Posted: 29 Jun 2019 08:05
by tatewise
As we discussed before in All in the Family (16887), you are dealing with two data items.
1) The FAM.CHIL tag that is within the Family record
2) The INDI record who is the child, i.e. FAM.CHIL>

So the iteration loop must step through FAM.CHIL[1], FAM.CHIL[2], FAM.CHIL[3], etc.
But the the functions matID(), matNAME(), etc, must operate on each INDI child record.
e.g.

Code: Select all

local ptrCHIL = fhGetItemPtr(ptrFAM, '~.CHIL')	-- No '>' so points to FAM.CHIL[1] 
while ptrCHIL:IsNotNull() do
	local ptrINDI = fhGetValueAsLink(ptrCHIL)	-- Get  pointer to child individual
	table.insert(tblFAM, fid)
	matID(ptrINDI)
	matNAME(ptrINDI)
	matSEX(ptrINDI)
	matLifeInf(ptrINDI)
	matCEM(ptrINDI)
	ptrCHIL:MoveNext('SAME_TAG') -- NEXT Child in FAM
end

Re: ITER troubles.

Posted: 30 Jun 2019 14:54
by Ron Melby
plain as the face on my head when you say it, dont know why I cant get that to stick in my head, on my face.