Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
When will VFP7 SP1 come out?
Message
From
07/11/2001 12:57:05
 
 
To
07/11/2001 05:01:44
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00577318
Message ID:
00578596
Views:
17
>Any thoughts on this now Jim?

Without seeing the whole thing, it's really hard to tell. Here is a repro based on my understanding of what you are doing. When using FOR EACH (#Define USEFOREACH .T.), I get a fatal exception on the m.oItem.Move(m.oRetained) line the first time through. When not using FOR EACH (#Define USEFOREACH .F.), it works fine. This moves 3 messages from the Inbox to a folder called JimTest which must already exist. Note it does not crash if the FOR EACH in MoveToRetainedFolder is used, it is the FOR EACHes in GetMessageRetainedFolder that cause the problem. Bottom line is that using FOR EACH to find an object reference, and using it later can be problematic.
#Define olFolderInbox  6
#Define USEFOREACH  	.F.

Local omail As Outlook.Application
Public ox
ox = Crea('mapitest')
ox.populatecollection()
Release ox
Return

Define Class mapitest As Session OlePublic

	omail = Null
	oNameSpace = Null
	OLSyncFolder = "JimTest"
	oColItemRefs = Null
	oInbox = Null

	Procedure Init
		With This
			.omail = Createobject('outlook.application')
			.oNameSpace = This.omail.GetNameSpace("MAPI")
			.oInbox = .oNameSpace.GetDefaultFolder(olFolderInbox).items
		Endwith
	Endproc

	Procedure populatecollection
		This.oColItemRefs = Createobject('Collection')

		Local nMsgIndex, nNumMessages, cAttFile, nAttachNum, lErrorOccured

		* Get the number of messages.
		m.nNumMessages = This.oInbox.Count

		If m.nNumMessages > 0
			* Run the following loop for the number of messages.
			For m.nMsgIndex = 1 To 3
				* Record a reference to this mail item.
				This.oColItemRefs.Add(This.oInbox.Item[m.nMsgIndex])
				* Process the next message (effectively: Skip -1).
			Endfor

			This.MoveToRetainedFolder(.T.)	&& Clears the collection.

		Endif	&& m.nNumMessages > 0

	Endproc

	Procedure GetMessageRetainedFolder
		Local loFolder, loSelFolder, lni, lnj
		loFolder = Null
		loSelFolder = Null

		If	USEFOREACH
			For Each loFolder In This.oNameSpace.Folders
				For Each loSubFolder In loFolder.Folders
					If Allt(loSubFolder.Name) == This.OLSyncFolder
						loSelFolder = loSubFolder
						Exit
					Endif
				Endfor
				If !Isnull(loSelFolder)
					Exit
				Endif
			Endfor
		Else
			For lni = 1 To This.oNameSpace.Folders.Count
				loFolder = This.oNameSpace.Folders.Item[lni]
				For lnj = 1 To loFolder.Folders.Count
					loSubFolder = loFolder.Folders.Item[lnj]
					If Allt(loSubFolder.Name) == This.OLSyncFolder
						loSelFolder = loSubFolder
						Exit
					Endif
				Endfor
				If !Isnull(loSelFolder)
					Exit
				Endif
			Endfor
		Endif && USEFOREACH

		Return loSelFolder
	Endproc

	Procedure MoveToRetainedFolder(tlClear)
	
		Local oItem, oRetained, lnItemCount, lni

		m.oRetained = This.GetMessageRetainedFolder()

		If	USEFOREACH
			For Each m.oItem In This.oColItemRefs.Item
				m.oItem.Move(m.oRetained) &&<-- THIS Guy hurts.
			Next m.oItem
		Else
			For lni = 1 To Alen(This.oColItemRefs.Item)
				This.oColItemRefs.Item[lni].Move(m.oRetained) 
			Next m.oItem
		Endif && USEFOREACH

		If Vartype(m.tlClear) == 'L' And m.tlClear
			This.oColItemRefs.Clear()
		Endif

	Endproc

Enddefine

Define Class collection As Custom
	Dimension Item[1] = Null
	Procedure Add(toObject)
		If Alen(This.Item) != 1 Or Type('this.item[1]') = "O"
			Dimension This.Item[ALEN(this.item)+1]
		Endif
		This.Item[ALEN(this.item)] = toObject
		Return
	Endproc

	Procedure Clear()
		For lni = 1 To Alen[this.item]
			This.Item[lni] = Null
		Endfor
		Dimension Item[1]
	Endproc

Enddefine
Jim Saunders
Microsoft
This posting is provided “AS IS”, with no warranties, and confers no rights.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform