Page 1 of 1

fhGetDisplayText - Anomaly or my error

Posted: 24 Oct 2022 17:32
by TMG_refugee
I am having a problem with my LUA learning effort I have the following script statements:

Code: Select all

if strType == 'BIRT' then
            strPointerDescription = fhGetDisplayText(pi)
            fhMessageBox(strPointerDescription)
            strPointerDescription = fhGetDisplayText(pi,'~.BIRT.PLAC', 'min')
            fhMessageBox(strPointerDescription)
end
I am using the fh plugin testing tool

At the first fhMessageBox I get this:
strPointerDescription global "Born January 1, 1945 in Hebron, Connecticut"

At the second fhMessageBox I get this:
strPointerDescription global ""

What am I doing wrong?

I got frustrated and actually copied the code from:
https://www.family-historian.co.uk/help/fh7-plugins/
FamilyHistorian API
Function Index
fhGeTDisplayText

Re: fhGetDisplayText - Anomaly or my error

Posted: 24 Oct 2022 17:47
by ColeValleyGirl
You don't show us where pi is set, but it looks as if you've created a pointer to the Birth fact, not to an individual.

Which would make the second reference trying to get the birth place of a birth, which doesn't exist...

The actual code in the Help file is:

Code: Select all

ptr = fhNewItemPtr()
ptr:MoveToFirstRecord("INDI")
 
-- Displays the Name of the Individual
strPointerDescription = fhGetDisplayText(ptr)
fhMessageBox(strPointerDescription)

-- Displays the Birth Information for the Individual
strPointerDescription = fhGetDisplayText(ptr,'~.BIRT')
fhMessageBox(strPointerDescription)

-- Displays the Birth Place for the Individual without the label 'Place: '
strPointerDescription = fhGetDisplayText(ptr,'~.BIRT.PLAC', 'min')
fhMessageBox(strPointerDescription)

Re: fhGetDisplayText - Anomaly or my error

Posted: 24 Oct 2022 19:14
by TMG_refugee
ColevalleyGirl.
This is the code that I have. I hope I didn't make any typos

Code: Select all

pi = fhNewItemPtr()  -- declare pointer
pi:MoveToFirstRecord('INDI')
while not pi:IsNull() do
   strPointerDescription = fhGetDisplayText(pi)
    while not pi:IsNull() do
           strPointerDescription = fhGetDisplayText(pi)
           strType = fhGetTag(pi)
                if strType == 'BIRT' then
                    strPointerDescription = fhGetDisplayText(pi)
                    fhMessageBox(strPointerDescription)
                    strPointerDescription = fhGetDisplayText(pi,'~.BIRT.PLAC', 'min')
                    fhMessageBox(strPointerDescription)

               end

    pi:MoveNextSpecial()
end
pi:MoveNext()
end

Re: fhGetDisplayText - Anomaly or my error

Posted: 24 Oct 2022 22:15
by tatewise
Sorry, but you are overloading the pi pointer.

In the outer loop, you are trying to use pi to point to successive Individual records.

But in the inner loop, you are using pi:MoveNextSpecial() which steps through all nested data fields.
So eventually pi points to a Birth Event with the 'BIRT' tag, which is what Helen is saying.
i.e. At that point pi is already pointing to INDI.BIRT

If you change fhGetDisplayText(pi,'~.BIRT.PLAC', 'min') to fhGetDisplayText(pi,'~.PLAC', 'min') it will work.