OLE Issue with Outlook

I have code that will paste information into an open message in Outlook, if there is no message being composed, it would start a new message. Prior to XOJO 2018 Release 2 this code worked quite well, now in Release 2, it mostly works, but it no longer catches the NilObjectException as indicated in the comment below.

Anyone have an idea as to why and/or what to do about it?

[code]dim d as new date
d.Day = d.day + ExpirationDays
dim HTMLB as String = Template_HTML.ReplaceAll("<%LargeFileLinks%>", Links_HTML).ReplaceAll("<%ExpirationDate%>", str(d.LongDate))
dim TextB as String = Template_Text.ReplaceAll("<%LargeFileLinks%>", Links_HTML).ReplaceAll("<%ExpirationDate%>", str(d.LongDate))
objApp = new OLEObject(“Outlook.Application”)
if objApp = nil then
dim c as new Clipboard
c.Text = TextB
MsgBox(“It appears that Outlook is not installed, the links have been copied to the Clipboard instead.”)
exit sub
else
try
objMail = objApp.ActiveInspector.CurrentItem 'This line is the one that is having an error
catch e as NilObjectException
try
objMail = objApp.CreateItem(0)
catch e2 as NilObjectException
dim c as new Clipboard
c.Text = TextB
MsgBox(“It appears that Outlook is not installed, the links have been copied to the Clipboard instead.”)
exit sub
end try
end try
if objMail <> nil then
objMail.Invoke(“Display”)
end if
try
if objMail <> nil then
objMail.Value(“HTMLBody”) = HTMLB + EndOfLine + EndOfLine + objMail.Value(“HTMLBody”)
else
dim c as new Clipboard
c.Text = TextB
MsgBox(“An error occured while copying the links to the email, the links have been copied to the Clipboard instead.”)
end if
catch e as OLEException
dim c as new Clipboard
c.Text = TextB
MsgBox(“An error occured while copying the links to the email, the links have been copied to the Clipboard instead.”)
end try
end if

if objMail <> nil then
objMail = nil
end if
[/code]

Even stranger, it works once compiled, but does not work from the debugger.

try objMail = objApp.ActiveInspector.CurrentItem 'This line is the one that is having an error catch e as NilObjectException

Well, I have no idea as to why this worked and now doesn’t anymore, but the way you code makes debugging hard. You don’t know for sure if .ActiveInspector is nil or if accessing it raises an OLEException, these things are afaik not documented at all and you have to tread carefully. I’d rewrite this like this to make it more debugger friendly:

dim objActiveInspector as OLEObject
try
objActiveInspector=objApp.ActiveInspector
catch err as OLEException
//handle
end
If objActiveInspector isa OLEObject then
dim objMail as OLEObject
try
objMail=objActiveInspector.CurrentItem
catch err as OLEException
//handle
end

Debugging this code should give you a better idea of what’s going on there.

A very valid point and no, these things aren’t well documented, but I have to get the job done, so I appreciate the input.