ComObjConnect() help

Get help with using AutoHotkey and its commands and hotkeys
User avatar
kczx3
Posts: 359
Joined: 06 Oct 2015, 21:39

ComObjConnect() help

16 Mar 2017, 14:35

Hey all,

This is my first dive into classes with AHK. I'm trying to do something fairly simple. I have a tray menu item that launches a function called changeControl(). This creates a new instance of my class call changeControl.

I have it correctly creating the email via the createCCEmail method but I am having trouble connecting onto the events of the email. I tried creating a nested class for the email's events and another for the events of an appointment item (we can worry about that later). I tried changing my menu item to launch an actual label instead of a function because i thought the problem was that my class instance was disappearing after the function returned but that still didn't seem to work. Below is a snippet my code. The menu item's function is at the bottom. This gets called correctly and the instance of changeControl is created and the email displays as desired. I just can't get the event sink to work.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

kon
Posts: 1680
Joined: 29 Sep 2013, 17:11

Re: ComObjConnect() help

16 Mar 2017, 15:16

My Changes are marked with ; <--. See my comments for more explanation.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


[Edited shortly after posting]
User avatar
kczx3
Posts: 359
Joined: 06 Oct 2015, 21:39

Re: ComObjConnect() help

16 Mar 2017, 15:50

Fantastic! So it seems my biggest mishaps were not saving a reference to the mailItem and misunderstanding the order of the arguments passed to the event handlers. I have the full thing working now. Thanks kindly!
kon
Posts: 1680
Joined: 29 Sep 2013, 17:11

Re: ComObjConnect() help

16 Mar 2017, 17:04

kczx3 wrote:So it seems my biggest mishaps were not saving a reference to the mailItem and misunderstanding the order of the arguments passed to the event handlers.
Yes. Also there is this one additional comment:
kon wrote:

Code: [Select all] [Download] GeSHi © Codebox Plus

;~ changeControl(itemName, itemPos, menuName) {
;~ ccEmail := new changeControl(itemName).createCCEmail() ; <-- This stores the return value of 'createCCEmail', not the new object.
;~ }

You may not have looked at this because I commented-out this portion. But, my comment is incorrect. It does not "store the return value of createCCEmail", but your version still needs to be changed too. (Split it into two lines as I have done in the auto-execute section of the code posted above. or maybe (ccEmail := new changeControl(itemName)).createCCEmail() - untested)
Ex:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
kczx3
Posts: 359
Joined: 06 Oct 2015, 21:39

Re: ComObjConnect() help

16 Mar 2017, 19:12

Yeah I did see that and some on the IRC said not to chain methods. I work with JavaScript a lot and really like being able to chain class methods so it's something I was comfortable with and thought to copy. I know that typically requires returning 'this' from every method though.
User avatar
kczx3
Posts: 359
Joined: 06 Oct 2015, 21:39

Re: ComObjConnect() help

17 Mar 2017, 06:38

Does it appear that I am properly cleaning things up? I am thinking that I need to create an __Delete() meta function that goes through and garbage collects any of my COM object references.
kon
Posts: 1680
Joined: 29 Sep 2013, 17:11

Re: ComObjConnect() help

20 Mar 2017, 18:30

Simply freeing the references to the COM objects is enough. And that should happen when you delete the object that contains the references.
User avatar
kczx3
Posts: 359
Joined: 06 Oct 2015, 21:39

Re: ComObjConnect() help

20 Mar 2017, 18:34

Ok. Wasn't sure because I'd assume that my object is getting delete quickly as I instantiate the class inside a function and nothing in the class is halting the script as far as I can tell

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], MaxAstro, Railang, Yahoo [Bot] and 31 guests