Page 1 of 2

Strange error while quitting application

PostPosted: Tue Dec 02, 2008 4:38 pm
by driessen
Hello,

I changed my errsysw.prg a little bit, so that the error.log is automatically mailed to me if a customer gets an error.

To do this, I use this code :
Code: Select all  Expand view
      TRY
         oOutLook := CreateObject("Outlook.Application")
         EmSend := .T.
      CATCH
         TRY
            oOutLook := CreateObject("Outlook.Application")
            EmSend := .T.
         CATCH
            EmSend := .F.
         END
      END

      TRY
         IF EmSend
            oMail         := oOutLook:CreateItem(olMailItem)
            oMail:Subject := ALLTRIM("Juda(32)-foutmelding - " + ALLTRIM(PAR->GKANTOOR))
            oMail:Body    := "Datum : " + DTOC(DATE()) + CRLF + "Uur : " + TIME()
            oMail:Recipients:Add("info@ma-consult.be")
            oMail:Attachments:Add("Error.log")
            oMail:Send()
            MsgAlert("Error.log has been send !!!","Error")
         ENDIF
      CATCH
         EmSend := .F.
      END

      CLOSE ALL

      SET RESOURCES TO
      ErrorLevel( 1 )
      QUIT


If I use this function, it always ends with :
Premature Array/Object Release detected 013440ec (the closing number changes each time)


I remarked (*) all the lines, starting with "oMail:", but the error still occurs. But if I also remark (*) the lines with "CreateObject()", the error does not occur.

What does this error mean ?
How can this problem be solved ?

Thanks a lot in advance for any help.

PostPosted: Tue Dec 02, 2008 10:41 pm
by James Bott
Michel,

Try putting a sysrefresh() in after oMail:send(). If that doesn't solve it, add a delay after oMail:send().

waitSeconds(3)

Regards,
James

PostPosted: Tue Dec 02, 2008 11:10 pm
by Antonio Linares
Michel,

Try these lines before calling QUIT:

oMail = nil
oOutLook = nil

PROBLEM SOLVED !!!

PostPosted: Wed Dec 03, 2008 9:08 am
by driessen
Thanks, guys, for your help.

Antonio, your suggestion solved my problem.

Have a nice day.

PostPosted: Wed Dec 03, 2008 4:23 pm
by hag
Driessen:
Is the code you posted the full code for the errsys email function. I think its a great idea and i will be trying it in my app. If its not the complete code please post the entire code or email it to me. I'm using harbour will it work in harbour.

Thanks

PostPosted: Wed Dec 03, 2008 5:37 pm
by driessen
Apart from the remarks by Antonio, that is indeed the source I added to the errorsysw.prg.

Good luck.

PostPosted: Wed Dec 03, 2008 5:42 pm
by hag
Thanks I'll let you know how it works.

PostPosted: Thu Dec 04, 2008 6:02 am
by hag
Driessen:
I gave it a try and i get the following dialog message
A program is trying to access e-mail addresses stored in Outlook. Do you want to do allow this?

If I say yes nothing happens.

Do you have any idea what my problem is?
I'm using the code you entered here.

PostPosted: Thu Dec 04, 2008 6:31 am
by hag
Driessen
Its stops running at oMail:Attachments:Add("Error.log"). If I remove this line it works.

Any suggestions?

PostPosted: Thu Dec 04, 2008 8:50 am
by driessen
Harvey,

Maybe you need to add the full pathname of error.log ?

It's working fine here.

PostPosted: Thu Dec 04, 2008 6:03 pm
by hag
Driessen:

Path worked. Thanks for the help.

PostPosted: Thu Dec 04, 2008 6:11 pm
by James Bott
Harvey,

This will automatically get you the current path of the EXE so you don't have to hard code the path.

cPath:= cFilePath( GetModuleFileName( GetInstance() ) )

Regards,
James

PostPosted: Thu Dec 04, 2008 6:12 pm
by hag
Thanks James.

PostPosted: Thu Dec 04, 2008 6:20 pm
by driessen
James,

Indeed, you are right but only if the data-files and the EXE-files are in the same directory.

In my case, they aren't.

PostPosted: Thu Dec 04, 2008 6:25 pm
by James Bott
Michel,

Then just add your data directory name to the path, something like this:

cPath:= cFilePath( GetModuleFileName( GetInstance() ) ) + "\data"

But I am not sure where the error.log is going to be written--in the default directory or in the EXE's directory.

James