RE-Decoded

A technical look at the Raiser's Edge API from Blackbaud


Feeds:

Close down or crash

June 29th, 2007 by David Zeidman

One of the basic principles that you need to learn when you start programming the API is that for top level object (constituents, gifts, funds, participants, etc) whenever you initialize the object you need to close it down. This is not too difficult to remember to do and you are swiftly reminded when you close the plug-in or the application (it crashes).

However there are some exceptions to this. When you loop a collection of top level records e.g. CGifts, using the for each construct you also have to close down the individual item. This goes against the above logic as you did not initialize it.

Below is an example of this:

Code:

'Just use anonymous to limit the number of gifts  

Dim oGifts As New CGiftsDim oGift As CGift  

oGifts.Init SessionContext, tvf_Gift_AnonymousOnly     

For Each oGift In oGifts     

    MsgBox oGift.Fields(GIFT_fld_Amount)
    oGift.CloseDown     

Next oGift     

oGifts.CloseDown
Set oGifts = Nothing

Another not so obvious time that the close down method has to be called is when you delete a record. When I first did this I did not think that I would need to close down because the gift was no longer in the system. In fact I assumed that by I would cause an error by trying to close down a gift because it no longer existed.

However the closedown mechanism does not close the actual gift down but closes the gift object. Until the gift is loaded the gift object is an empty shell with some initialization done on it. The closedown method will uninitialize it whether or not there is a current gift loaded.

No related posts.

Posted in Beginner | 4 Comments »

4 Responses

  1. RE-Decoded » Blog Archive » Custom user defined business rules Says:

    [...] We have to close down each gift as we go around the loop. (see Close down or crash) [...]

  2. COMException 0x80010105 when retrieving participant event data - Blackbaud User Society - Forum Says:

    [...] objects. This is the same when you look at the gifts a constituent has. See my blog article: RE-Decoded ? Blog Archive ? Close down or crash I am not sure if this is the cause of your problem but it will at least get rid of memory leaks [...]

  3. COMException 0x80010105 when retrieving participant event data - Blackbaud User Society - Forum Says:

    [...] objects. This is the same when you look at the gifts a constituent has. See my blog article: RE-Decoded ? Blog Archive ? Close down or crash I am not sure if this is the cause of your problem but it will at least get rid of memory leaks [...]

  4. Creating A New Action in VBA - Blackbaud User Society - Forum Says:

    [...] you should also always closedown top level objects that you initialise (and some that you don’t – see here) So that you should have at the end: action1.Closedown set action1 = nothing David [...]

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Switch to our mobile site