* Check if source is new or existing

Writing and using plugins for Version 5 and above.
Post Reply
avatar
JoopvB
Famous
Posts: 197
Joined: 02 May 2015 14:32
Family Historian: V7

Check if source is new or existing

Post by JoopvB » 04 Feb 2021 13:49

In a DEA plugin I test if a Prepared Citation exists to make sure it's run as a DEA.
In addition I test the length of the fields table in the pCite Object to determine if the Source is newly created (empty source) or an existing one (if > 3).

If however CP changes the pCite Object the test may be invalidated. Is there another and more failsafe way to do this test?

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

Re: Check if source is new or existing

Post by ColeValleyGirl » 13 Feb 2021 08:37

By
JoopvB wrote:
04 Feb 2021 13:49
CP changes the pCite Object
do you mean them changing the architecture in the future? If so, there's no way to protect against that, but I think it unlikely to change, at least for the lifetime of V7.

avatar
JoopvB
Famous
Posts: 197
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Check if source is new or existing

Post by JoopvB » 14 Feb 2021 18:13

What I mean is that in object oriented programming it is good practice to use methods to access data in an object. Thereby allowing the owner (CP in this case) of the object to change/extend the internals of the object without any consequence for the users.

As it is, I am now using data inside the pCite object/table directly... hence my question (I found no function/method to determine if a source is new/empty).

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

Re: Check if source is new or existing

Post by ColeValleyGirl » 14 Feb 2021 18:22

There is no so such function unfortunately.

avatar
JoopvB
Famous
Posts: 197
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Check if source is new or existing

Post by JoopvB » 15 Feb 2021 10:06

Thanks Helen, unfortunately indeed.

Makes me wonder how all the DEA plugins verify that the the source/citation is a new and empty one. I would expect this to be an important check.

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

Re: Check if source is new or existing

Post by ColeValleyGirl » 15 Feb 2021 10:20

Not all DEAS require that the source is new, merely that a prepared citation exists. Some of them check for specific field values, so the last thing they need is an empty/new source.

avatar
JoopvB
Famous
Posts: 197
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Check if source is new or existing

Post by JoopvB » 16 Feb 2021 11:25

Agreed Helen, 'not all', but (as a retired mathematician :)) that means that at least one remains. And if I'm guessing right, you as a experienced DEA developer know which one (maybe one of your own). Which brings me back to my original question... how have you (or anyone that did DEA's that needed fresh sources/citations) verified it's freshness?

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

Re: Check if source is new or existing

Post by ColeValleyGirl » 16 Feb 2021 11:48

At present, yours is the only DEA that needs a new source; ALL the others need an existing one.

I have one to develop that will need a new source (based on an existing plugin written by somebody else for V6) but I haven't started work on that. I can't think of a better check than your (other than exhaustively testing that all fields are empty).

Post Reply