* fhGetDisplayText - Anomaly or my error

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
avatar
TMG_refugee
Diamond
Posts: 97
Joined: 14 Nov 2015 15:44
Family Historian: V7

fhGetDisplayText - Anomaly or my error

Post by TMG_refugee » 24 Oct 2022 17:32

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

User avatar
ColeValleyGirl
Megastar
Posts: 4853
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: fhGetDisplayText - Anomaly or my error

Post by ColeValleyGirl » 24 Oct 2022 17:47

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)

avatar
TMG_refugee
Diamond
Posts: 97
Joined: 14 Nov 2015 15:44
Family Historian: V7

Re: fhGetDisplayText - Anomaly or my error

Post by TMG_refugee » 24 Oct 2022 19:14

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

User avatar
tatewise
Megastar
Posts: 27080
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: fhGetDisplayText - Anomaly or my error

Post by tatewise » 24 Oct 2022 22:15

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.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Post Reply