Items.Get* Methods

  • Thread starter Thread starter Craig Buchanan
  • Start date Start date
C

Craig Buchanan

A MAPIFolder's Items collection includes GetFirst, GetPrevious, GetNext,
GetLast methods. Considering that the Items collection has the enumerator,
what is the purpose of these methods? Are they for use by the various
data-entry forms? I see that they have menu options that correspond to
these methods.

Thanks,

Craig Buchanan
 
These methods are designed to act as an enumerator. E.g.

Msg = Items.GetFirst
while Msg != NULL
//do something
Msg =Items.GetNext
next

They do not correspond to any menu items. What you see in the Inspector
menus/toolbars is tied to the items in a particular explorer sorted in a
particular order. The Items collection can be sorted in a totally different
way.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Dmitry-

You can also do

For Each Item In Folder.Items
'do something
Next

Because of this, it seems like the Get* method are redundant. Am I still
missing something?

Craig
 
Craig Buchanan said:
You can also do

For Each Item In Folder.Items
'do something
Next

Because of this, it seems like the Get* method are redundant. Am I
still missing something?

Not really, but GetFirst/GetNext are a different way to do things. You
could also do something like "for i = 1 to items.count Items.GetItem(i)",
too.

It's no more redundant than, say, having both + and - operators, when
after all you could just do "i = i + (-1)" instead of "i = i - 1".
Sometimes it's just nice to have a bit more flexibility.

-- dan
 
yes, you can use "for ...each". You can also use a "for i =1 to Count" loop.
Whatever suits your particular task and skills better.
GetFirst/GetNext/etc just correspond more closely to the IMAPITable Extended
MAPI object used to expose the folder contents table: it uses a cursor to
navigate its data. "for each" enumerator is more generic even if it fits
fairly well with the MAPI objects.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Dmitry-

When I saw the Get* methods, my initial suspicion was that the API didn't
convert the raw data to an object until a Get* method was called (as opposed
to converting each row of data to an object, then adding the object to the
collection). I thought I might model my custom collection class on the MAPI
folder object.

Upon furher investigation, I've discovered that one can create a custom
enumeration when each object could be created on the fly based on raw data.

It also seems that the Get* methods make it easier for the visual interface
to move between items in a folder, like what can be done for mail messages
(e.g. View | Previous | Item menu).

BTW, the IMAPITable actually an ADO type object?

Thanks for the input.

Craig
 
Back
Top