Jump to content



Photo

ByRef support through COM


  • Please log in to reply
12 replies to this topic

#1 big_daddy

big_daddy

  • Moderators
  • 2,524 posts

Posted 21 June 2007 - 04:18 PM

I was trying to help someone here in the support forum pass some variables between Excel/Word. In doing so I came to the conclusion AutoIt does not support ByRef variables through COM.
  • Create a Word Document
  • Press Alt-F11
  • Double Click "ThisDocument"
  • Paste the following macro
  • Saveas "ByRef.doc"
Sub MacroTestByRef(ByRef v_Arg)     v_Arg = "After" End Sub


I would have expected the following to write "After" to the console, but instead it still has the value of "Before".








#2 /dev/null

/dev/null

    Universalist

  • MVPs
  • 2,946 posts

Posted 21 June 2007 - 04:32 PM

isn't that a know limitation?

From the help file: Obj/COM Reference

Limitations on COM Events in AutoIt
Some Objects (like the 'WebBrowser') pass arguments to their Event Functions 'by reference'. This is intended to allow the user change these arguments and passing it back to the Object. However, AutoIt uses it's own variable scheme, which is not compatible to COM variables. This means that all values from Objects need to be converted into AutoIt variables, thus loosing the reference to the original memory space. Maybe in the near future we can solve this limitation for you !


Edited by /dev/null, 21 June 2007 - 04:33 PM.

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

#3 big_daddy

big_daddy

  • Moderators
  • 2,524 posts

Posted 21 June 2007 - 06:35 PM

I thought I'd remembered reading something like that before. Although this has nothing to do with events, I'm guessing it is due to the same limitation.

#4 DaleHohm

DaleHohm

    Think of IE as an API...

  • MVPs
  • 5,897 posts

Posted 21 June 2007 - 07:25 PM

Well shoot. I use byRef throughout IE.au3 thinking that I was saving resources by no cloning the Object variable over and over again... if the architecture requires cloning anyway, the the restrictions that byRef creates are unwarranted (primarily not being able to nest _IE function calls inside eachother).

Need to do some of my own testing...

Dale
IE.au3 issues with Vista - Workarounds, Automate input type=file (Related)SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=YFree Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curlMSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model,Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbeddedFind and harvest Enum constants for COM codeAutoIt Snippets Database - you too can contribute!Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your troubleDoesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

#5 big_daddy

big_daddy

  • Moderators
  • 2,524 posts

Posted 31 July 2007 - 02:26 AM

Any developers care to comment?



#6 big_daddy

big_daddy

  • Moderators
  • 2,524 posts

Posted 02 February 2008 - 03:26 PM

I still think this would be a great limitation to overcome.



#7 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 02 February 2008 - 03:37 PM

I don't think it's going to happen. I've mentioned it before, but we can't even use ByRef on built-in functions. It's not a trivial issue to solve, particularly since nobody wants to work on it. Until we figure out how to modify parameters ByRef for built-in functions, COM isn't going to get it either.

#8 GioVit

GioVit

    Adventurer

  • Active Members
  • PipPip
  • 138 posts

Posted 22 February 2008 - 01:01 AM

I don't think it's going to happen. I've mentioned it before, but we can't even use ByRef on built-in functions. It's not a trivial issue to solve, particularly since nobody wants to work on it. Until we figure out how to modify parameters ByRef for built-in functions, COM isn't going to get it either.


why not considere events as a special type of function and define it with a special keyword (like "Event Func") so it can only be called by the COM object and have a different behaviour when pass arguments by reference?

because events are mostly called by COM object not by user

Sorry if I can't be more explicit, my english is limited

GioVit

#9 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 22 February 2008 - 02:21 AM

What do events have to do with by reference? An event can't take a parameter by reference.

#10 GioVit

GioVit

    Adventurer

  • Active Members
  • PipPip
  • 138 posts

Posted 22 February 2008 - 03:38 PM

What do events have to do with by reference? An event can't take a parameter by reference.

Here is an example

in the next code I define an event called "EdEvent_EndEdit" it have 4 arguments:

1) if you add to any of this arguments the keyword ByRef then an error occurs (Expected a variable in user function call.)
2) if you don't then you can't control the behavior of the edited cell because the changes in the arguments value are ingnored by the object

if you dont have "OWC11.dll" you can download it Here

The help file of this object, after installed, is in:
"[Drive where you intalled it]:\Program Files\Common Files\Microsoft Shared\Web Components\11\1033\OWCDSS11.CHM"

And the expalnation of the event "EndEdit" can be found in the help file with this path:
"Programming Information/Events/E/EndEdit Event"

AutoIt         
#include <GUIConstants.au3> #NoTrayIcon ;Vars Dim Const $xlToRight = -4161 ;0xFFFEFBF dim Const $ssClear = 10002 Dim $oMyError Global $oExcel, $oEvent Global $OrdDef [1][4] = [[0,0,0,0]] Global $OrdSaved = True Global $CurOp = "", $CurRow, $CurCol $oMyError = ObjEvent("AutoIt.Error","MyErrFunc") ; Install a custom error handler ;MsgBox(64,"Windowdir", @WindowsDir) InitExcel() ;Declare objects     ;Main Gui GuiCreate("Excel Object", 802, 590,(@DesktopWidth-802)/2, (@DesktopHeight-590)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) $GUI_ActiveX = GUICtrlCreateObj ($oExcel, 10, 10 , 780 , 550) GUICtrlSetState($GUI_ActiveX, $GUI_HIDE) ;GUICtrlSetStyle ( $GUI_ActiveX,  $WS_HIDE ) ;GUICtrlSetResizing ($GUI_ActiveX,$GUI_DOCKAUTO)    ; Auto Resize Object     GuiSetState() EditOrder() While 1     $msg = GuiGetMsg()     Select     Case $msg = $GUI_EVENT_CLOSE         ExitLoop     EndSelect WEnd Exit Func InitExcel()     $oExcel = ObjCreate("OWC11.spreadsheet"); Default to 2003     If not IsObj($oExcel) Then         $oExcel = ObjCreate("OWC10.spreadsheet"); Office XP         EndIf     IF not IsObj($oExcel) Then         $oExcel = ObjCreate("OWC00.spreadsheet"); Office 2000     EndIf     If Not IsObj($oExcel) Then        MsgBox(0,"Reply","No se encontro el Objeto Excel",4)        Exit    EndIf     $oEvent = ObjEvent($oExcel,"EdEvent_") EndFunc Func EditOrder()     $CurOp = "EditOrder"     GUICtrlSetState($GUI_ActiveX, $GUI_SHOW)        with $oExcel             .Activewindow.DisplayWorkbookTabs = False             .DisplayToolbar = False             .Autofit = True             .MoveAfterReturnDirection = $xlToRight             $oEvent = ObjEvent($oExcel,"EdEvent_")             GUICtrlSetState($GUI_ActiveX, $GUI_SHOW)         EndWith     EndFunc     Func EdEvent_EndEdit($Accept, $FinalValue, $Cancel, $ErrorDescription)     MsgBox(64,"FinalValue", $FinalValue.Value)     if $FinalValue > 4 Then         $FinalValue.Value = $FinalValue.Value * 2     Else         $Cancel.Value = True     EndIf EndFunc     ;This is Sven P's custom error handler Func MyErrFunc()   $HexNumber=hex($oMyError.number,8)   Msgbox(0,"AutoItCOM Test","We intercepted a COM Error !"       & @CRLF  & @CRLF & _              "err.description is: "    & @TAB & $oMyError.description    & @CRLF & _              "err.windescription:"     & @TAB & $oMyError.windescription & @CRLF & _              "err.number is: "         & @TAB & $HexNumber              & @CRLF & _              "err.lastdllerror is: "   & @TAB & $oMyError.lastdllerror   & @CRLF & _              "err.scriptline is: "     & @TAB & $oMyError.scriptline     & @CRLF & _              "err.source is: "         & @TAB & $oMyError.source         & @CRLF & _              "err.helpfile is: "       & @TAB & $oMyError.helpfile       & @CRLF & _              "err.helpcontext is: "    & @TAB & $oMyError.helpcontext _             )   SetError(1) ; to check for after this function returns Endfunc


also the AutoIt help File say

Limitations on COM Events in AutoIt



Some Objects (like the 'WebBrowser') pass arguments to their Event Functions 'by reference'. This is intended to allow the user change these arguments and passing it back to the Object. However, AutoIt uses it's own variable scheme, which is not compatible to COM variables. This means that all values from Objects need to be converted into AutoIt variables, thus loosing the reference to the original memory space. Maybe in the near future we can solve this limitation for you !

Is there other way to solve this?

Thanks in advance

#11 Valik

Valik

    Former developer.

  • Active Members
  • PipPipPipPipPipPip
  • 18,879 posts

Posted 22 February 2008 - 03:56 PM

Ahh, I guess I should have re-read the thread to see what it was really about.

I've just opened ticket #134 so this won't get lost. It's incredibly low priority, I have a million other things to do first.

#12 GioVit

GioVit

    Adventurer

  • Active Members
  • PipPip
  • 138 posts

Posted 22 February 2008 - 04:40 PM

Ahh, I guess I should have re-read the thread to see what it was really about.

I've just opened ticket #134 so this won't get lost. It's incredibly low priority, I have a million other things to do first.


Thank you anyway

I hope other users understand the importance of this change, in order to increase the priority.

Thanks again Valik

#13 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 23 February 2008 - 01:54 AM

It gets done when it gets done. No questions ask. They develop this in their own time!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users