AutoHotkey Community

It is currently May 26th, 2012, 12:26 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 82 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next
Author Message
PostPosted: December 9th, 2007, 3:49 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
?something had talked about doing, finally got around to.

slightly tested, may need some bug work.


essentially allows 'dropping' in visual basic objects and such, without having to use VB to manipulate them.

syntax basically:
Code:
1. make sure you call com_CoInitialize()

2. name the object HANDLE with '#_' prefix as in:

#_objWord  := com_CreateObject("Word.Application")


3. Use 'VB like syntax' as you please.. ex:

#_objDoc := ez_invoke("objWord.Documents.Open", Master_File)


4. for assignments use "=":

ez_invoke("objWord.Visible=","True")



5. To reference sub items use "[]".     (in VB "()" is used). ex:

mmtextfield3 := ez_invoke("objDoc.MailMerge.Fields[3].code.Text")


}} Kind of neat {{


6. To reference other objects prefix with "+" before object descriptor.


ez_invoke("ObjectX.+ObjectY")


i think that covers it, mostly.


additions:

A) Can use ' or "" for sub items as in
ez_invoke("object.property[""Whatever is X""]")  or ez_invoke("obj.prop['this is "OK" too'].method[3]")

B) Can use =+ for assigning one object with value of another's pointer as in ez_invoke("this.object =+ secondobject.property.method", with,these,params, optional)


oh,


7. reinvoke() to rebuild reference table.  For example,  if you've opened a new doc,  "document.page(1)" points to old and needs a reinvoke.

So, for example: if #_objDoc gets a new handle (ie. new document),  need:


ez_reinvoke("objDoc.MailMerge.Fields[3].code.Text")

first time you access.  (after that use regular ez_invoke() to take advantage of chache --> ie. faster!)....  need to reinvoke based on right-most object/property/method.  (ie. if you've reinvoked objDoc...Fields[4] you still need to reinvoke objDoc Fields[3]  and objdoc..Fields[4].code.text first time you access them. ) Suggested to just use new object handle when object or key branch changes  and just use invoke.  eg:  #_objDoc2, then #_objDoc3, etc...

UPDATED:  ez_reinvoke@(skip#, "Object.xx.xxx")


ie.  to reinvoke at the 4th object,  would use:

ez_reinvoke@(4,"object.o1.o2.o3.o4.o5")


it will also RELEASE that object *IF* you set Ez_Extra_Safe_Revoke global var to 1 or (2 for release *all* objects in chain).



8. copy and place in EZ.ahk in LIB folder.


9.  NEEDS SEAN'S  COM.AHK !!!!!!


note: object handle is called #_Object..   but inside the ez_invoke you just call it Object  ie.  drop the #_ for reference inside of ez_invoke.


complete handle tree is returnedas :  #_Object#_Inner_object#_Property#_etc   is returned so you can directly access any individual handle... etc.




updated to allow ["Whatever is here"],
such as ez_invoke("objVoice.GetVoices[""Name=Microsoft Mary""].Item", 0 ) and =+ assignments, and ' inplace of " if you desire.


but reserves a var per invoke so if the "..." changes often or much, best to use regular ez_invoke to set another var to value, and then use that.

anyhow

newest June 2008
ver
Code:


ez_revoke(object, skip = 1, xtra_safe = 0) { ;ez_revoke("object.this.that.whatever.x",3)  ==> starts w/ object #4

   global
   static illegal := "[^\w#@$?\[\]]"
   local Released
   
   local myobject, position, resul, result, resultisQ, resulted, resultedQ, resultedQS, assem
   
   ;skip--
   ;if skip < 1
   ;   skip = 1
   if  Ez_Extra_Safe_Revoke ;; Global Var Ez_Extra_Safe_Revoke  to override globally
      xtra_safe = 1
      
   myobject := "#_" . regexreplace(object, "\.", "#_", parts)    
   position = 1
   loop {
         if !(position := regexmatch(myobject, "\#_(?<t>\w+)(?<tisQ>\=)?(?:\[(?:(?<ted>\w+)|""(?<tedQ>[^""]*)""|'(?<tedQS>[^']*)')\])?", resul,  position)
               + strlen(resul) )
         break
      
      assem .=  regexreplace(resul,illegal,"?")
      ;;debug("assem inside revoke is " assem)
      ;debug("resul " resul "`nassem " assem)
      ;Xbug("assem is " assem )
      
      ;debug(a_index "vs skip at " skip)
      
      if  (a_index <= skip)
         continue
         
      
      
      if !Released and (%assem% > 0) { ; (a_index = 1) and
         if Xtra_safe or (a_index = 1)  ; ie.  release only if object  unless extra_safe mode..
            com_Release(%assem%)
         if !Xtra_safe
            Released = 1
      ; @%assem% = 1
      }
      ;debug(a_index "-->" assem  "==" %assem%)
      %assem% =
   }
}

ez_release(object) {

   if !(object := regexreplace(object,"\..*$"))
      return
   
   Full_object = #_%object%
   if !(ObjectP := %Full_Object%)
      return
      
   com_Invoke(ObjectP, "Quit")
   return com_release(ObjectP)

}

;ez_invoker & _reinvoker are SUPPOSED to release as they build--> am not sure is working or note... needs careful test!!!!

ez_reinvoke@(  skip , object , arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe",argA="vT_NoNe"  )  {

   ez_revoke(object,skip)
   return ez_invoke( object,  arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA )

}

ez_reinvoke( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe",argA="vT_NoNe"  )  {

return ez_invoke( object,  arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA,1 )

}

ez_reinvoker( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe",argA="vT_NoNe"  )  {

return ez_invoke( object,  arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA,-1 )

}

ez_invoker( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe",argA="vT_NoNe"  )  {

return ez_invoke( object,  arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA,-2 )

}

ez_invoke( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe",argA="vT_NoNe", revoke = "" ) {
   ;debug(object "--: " arg1)
   if instr(object,"=+") and  regexmatch(object,"^\s*(?<object>.+?)\s*=\+\s*(?<param>.+)$",_)
      return revoke ? ez_reinvoke(_object "=", "+" ez_invoke(_param, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA,revoke) ) : ez_invoke(_object "=", "+" ez_invoke(_param, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8, arg9,argA,revoke ) )
      ;
   if !( (instr(object,".+") ?  regexmatch(object,"^\s*(?<object>.+?)\.(?<obj>\+)(?<param>.+?)\s*$",_) : regexmatch(object,"^\s*(?<object>.+?)((?<param>\w+=?)(?:\[(?<dualparam>\w+|""[^""]*""|'[^']*')\])?(?<dparamQ>=)?"
   ;;(?<param>\w+|\[(?:\w+|""[^""]*"")\]=?"
      ;; (?<param>\w+(?:\[(?<dualparam>\w+|""[^""]*"")\])?=?"
;      . "(?:\."
;         . "(?<param>"
;            . "(?:\w+"
;               . "(?:\["
;                  . "(?:""[^""]*""|\w+)"
;               . "\])?"
;               . "(?:\.\w+)?"
;            . ")+"
;         . "[=]?)"
      . ")?\s*$",_) ))
   ;regexmatch(object,"^\s*(?<object>.+?)\.(?<obj>\+)?(?<param>[\w=]+)\s*$",_) )
      return
      
   ;debug("object is" _object "`nparam is " _param)
/*
   if ! object or !( pos := instr(object,".",0,0))
      return      
   param := substr(object,pos + 1)
   
   object := substr(object,1, pos - 1)
*/      
   if  ( _object != _object + 0 )
      _object := ez_invoke_findhandle(_object,revoke)
   
   
   if _obj {
   
      if  ( _param != _param + 0 )
         _param := ez_invoke_findhandle( _param , revoke)  ; "#_" .

      _param := "+" . _param
   }
   
;   if (A_FormatInteger = "H") {
;      ;swapback = 1
;      SetFormat, Integer, D
;      tmp := Com_Invoke(_object, _param , arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
;      setFormat, Integer, H
;      return tmp
;   } else
   
      return (_param = "") ? Com_Invoke(_object, arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA) : (_dualparam = "") ?  Com_Invoke(_object, _param , arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA) : Com_Invoke(_object, _param . _dparamQ,regexreplace( _dualparam,"^['""]|['""]$"), arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
   

}

ez_invoke_findhandle(object,revoke ="") {   

   global
   static illegal := "[^\w#@$?\[\]]"
;   static idCounter = 0

   local myobject, handle, parts, resul, result, resulted, resultisQ, resultedQ, resultedQS,position, assem, value, Ovalue,OOvalue, assem_old, revoker ; , mystart,the_Obj,the_,the_rest

   ;if !regexmatch(myobject,"^(?<obj>\w+)(?<rest>.*)$",the_)
   ;   return
   
   ;the_obj := "#_" . the_obj
   
   myobject := "#_" . regexreplace(object, "\.", "#_", parts)
   ;myobject := "#_" . %the_obj% . regexreplace(the_rest, "\.", "#_", parts)
   
   
   
   ;Xbug( "my object is " myobject  "--> " %myobject%)
   
   if  revoke {
      if  (revoke < 0) {
   
         revoke += 2
         revoker = 1
         ;debug("revoker is " revoker)
      }
      
   ;   idCounter++
   }
   
   ;debug( (@%myobject%))
   if  !(revoke or  parts or regexmatch(myobject, illegal) ) and  ((handle := %myobject%)  > 0 ) ; and !(@%myobject%)  ; or (strlen(myobject) > 254)
      return  handle
      
   ;hmmm
   ;   if  !Revoke &&   !parts &&  !regexmatch(myobject, illegal)  &&   ((handle := %myobject%)  > 0 )
;   if  !(revoke or  parts or  regexmatch(myobject, illegal) ) and  ((handle := %Smyobject%)  > 0 )
;   if  !(revoke or  parts or  regexmatch(myobject, illegal) ) and  (Smyobject := regexreplace(myobject,illegal,"?"))  and  ((handle := %Smyobject%)  > 0 )  ; or (strlen(myobject) > 254)

   position = 1
   
   loop {
      if !(position := regexmatch(myobject, "\#_(?<t>\w+)(?<tisQ>\=)?(?:\[(?:(?<ted>\w+)|""(?<tedQ>[^""]*)""|'(?<tedQS>[^']*)')\])?", resul,  position)
               + strlen(resul) )
         break
      
      assem .=  regexreplace(resul,illegal,"?")
      ;debug("resul " resul "`nassem " assem)
      ;Xbug("assem is " assem )
      
      if (value := %assem%) and (!revoke or  (a_index = 1)   ) and (Ovalue := value) { ; (strlen(assem) < 254) and; (revoke or @%assem%)
         ;Xbug( "value = assem ==> " value)
         continue
      
      }
      
      if !Ovalue
         return
/*
      ; this.that[3].#[rr].
      if !Ovalue {
         if (a_index = 1) {
            value := substr(assem,3)
            if (Ovalue := %value%) > 0
               continue
         }
         
         return
      }   
*/
      
      ;debug(" result is" result " and resulted is" resulted . resultedQ "`n ovalue is" Ovalue  )
      if revoke
         assem_old := %assem%
         
      if revoker
         OOvalue := Ovalue
      ;Xbug("going to set Ovalue with current ovalue = " ovalue " and result at " result)
      
      @%assem% =
      %assem% := Ovalue := (resulted .= resultedQ . resultedQS) ? com_invoke(Ovalue, result . resultisQ, regexreplace(resulted,"\Q#_\E","."))  : com_invoke(Ovalue, result)
      
      if revoker  {
         if (assem_old > 0) and (assem_old <> Ovalue) ; and (a_index > 1)
            com_release(assem_old)
         ;debug(" assem old"  assem_old)
         if  (OOValue > 0) and (OOValue <> Ovalue) and  (a_index > 2)
            com_release(OOvalue)
         ;debug("OOvalue " OOvalue)
      }   
      ;debug("after revoker and a index is" a_index)
      ;%assem% := Ovalue := (resulted .= resultedQ . resultedQS) ? (result = "_") ? com_invoke(Ovalue,  regexreplace(resulted,"\Q#_\E",".")) : com_invoke(Ovalue, result . resultisQ, regexreplace(resulted,"\Q#_\E","."))  : com_invoke(Ovalue, result)
      
      ;debug( resulted ? "Ovalue, result, resulted, " Ovalue "," result "," resulted        : "")
      ;debug("assem" assem "`nresulted ? " resulted "`nOvalue , result"  Ovalue "," result)
      ;Xbug("set assem  on Ovalue <<-" Ovalue)
      
   
   }
   
   handle := %assem%
   ;debug(handle "is result")
   return handle
         
}



; -------------------------------------------------------------------

Com_RegisterCallback(FunctionName, Options = "", ParamCount = "", EventInfo = "") {
   
   global VProtectOFF
   
   address := (EventInfo = "") ?  (ParamCount = "") ? (Options = "") ? RegisterCallback(FunctionName) : RegisterCallback(FunctionName,Options) : RegisterCallback(FunctionName,Options, ParamCount) : RegisterCallback(FunctionName,Options, ParamCount, EventInfo)
   
   ;if (Address := RegisterCallback(FunctionName, Options , ParamCount , EventInfo ) ) and  VProtect
   if !VProtectOFF
      DllCall("VirtualProtect", "uint", Address, "uint", 8, "uint", 0x40, "uint*", 0)
      
   return Address
 
 }

new ver
Code:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EZ_INVOKE() ;;;;;;;;;;;;;;;;;;;;;;;;
;
;
; for  z = xxx.xx[3]  // z[3]  use xxx.xx[3].item[3]//
;

ez_reinvoke( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe",argA="vT_NoNe"  )  {

return ez_invoke( object,  arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA,1 )

}

ez_invoke( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe",argA="vT_NoNe", revoke = "" ) {
   ;debug(object "--: " arg1)
   if instr(object,"=+") and  regexmatch(object,"^\s*(?<object>.+?)\s*=\+\s*(?<param>.+)$",_)
      return revoke ? ez_reinvoke(_object "=", "+" ez_invoke(_param, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA,revoke) ) : ez_invoke(_object "=", "+" ez_invoke(_param, arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8, arg9,argA,revoke ) )
      ;
   if !( (instr(object,".+") ?  regexmatch(object,"^\s*(?<object>.+?)\.(?<obj>\+)(?<param>.+?)\s*$",_) : regexmatch(object,"^\s*(?<object>.+?)((?<param>\w+=?)(?:\[(?<dualparam>\w+|""[^""]*""|'[^']*')\])?(?<dparamQ>=)?"
   ;;(?<param>\w+|\[(?:\w+|""[^""]*"")\]=?"
      ;; (?<param>\w+(?:\[(?<dualparam>\w+|""[^""]*"")\])?=?"
;      . "(?:\."
;         . "(?<param>"
;            . "(?:\w+"
;               . "(?:\["
;                  . "(?:""[^""]*""|\w+)"
;               . "\])?"
;               . "(?:\.\w+)?"
;            . ")+"
;         . "[=]?)"
      . ")?\s*$",_) ))
   ;regexmatch(object,"^\s*(?<object>.+?)\.(?<obj>\+)?(?<param>[\w=]+)\s*$",_) )
      return
      
   ;debug("object is" _object "`nparam is " _param)
/*
   if ! object or !( pos := instr(object,".",0,0))
      return      
   param := substr(object,pos + 1)
   
   object := substr(object,1, pos - 1)
*/      
   if  ( _object != _object + 0 )
      _object := ez_invoke_findhandle(_object,revoke)
   
   
   if _obj {
   
      if  ( _param != _param + 0 )
         _param := ez_invoke_findhandle( _param , revoke)  ; "#_" .

      _param := "+" . _param
   }
   
;   if (A_FormatInteger = "H") {
;      ;swapback = 1
;      SetFormat, Integer, D
;      tmp := Com_Invoke(_object, _param , arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
;      setFormat, Integer, H
;      return tmp
;   } else
   
      return (_param = "") ? Com_Invoke(_object, arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA) : (_dualparam = "") ?  Com_Invoke(_object, _param , arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9,argA) : Com_Invoke(_object, _param . _dparamQ,regexreplace( _dualparam,"^['""]|['""]$"), arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
   

}

ez_invoke_findhandle(object,revoke ="") {   

   global
   static illegal := "[^\w#@$?\[\]]"

   local myobject, handle, parts, resul, result, resulted, resultisQ, resultedQ, resultedQS,position, assem, value, Ovalue

   myobject := "#_" . regexreplace(object, "\.", "#_", parts)    
   
   
   ;Xbug( "my object is " myobject  "--> " %myobject%)
   
   
   
   if  !(revoke or  parts or regexmatch(myobject, illegal) ) and  ((handle := %myobject%)  > 0 )  ; or (strlen(myobject) > 254)
      return  handle
      
   ;hmmm localize SmyObject :>
   ;   if  !Revoke &&   !parts &&  !regexmatch(myobject, illegal)  &&   ((handle := %myobject%)  > 0 )
;   if  !(revoke or  parts or  regexmatch(myobject, illegal) ) and  ((handle := %Smyobject%)  > 0 )
;   if  !(revoke or  parts or  regexmatch(myobject, illegal) ) and  (Smyobject := regexreplace(myobject,illegal,"?"))  and  ((handle := %Smyobject%)  > 0 )  ; or (strlen(myobject) > 254)

   position = 1
   loop {
      if !(position := regexmatch(myobject, "\#_(?<t>\w+)(?<tisQ>\=)?(?:\[(?:(?<ted>\w+)|""(?<tedQ>[^""]*)""|'(?<tedQS>[^']*)')\])?", resul,  position)
               + strlen(resul) )
         break
      
      assem .=  regexreplace(resul,illegal,"?")
      ;debug("resul " resul "`nassem " assem)
      ;Xbug("assem is " assem )
      
      if (value := %assem%) and (!revoke or (a_index = 1) ) and (Ovalue := value) { ; (strlen(assem) < 254) and
         ;Xbug( "value = assem ==> " value)
         continue
      
      }
      
      if !Ovalue
         return
/*
      ; this.that[3].#[rr].
      if !Ovalue {
         if (a_index = 1) {
            value := substr(assem,3)
            if (Ovalue := %value%) > 0
               continue
         }
         
         return
      }   
*/
      
      ;debug(" result is" result " and resulted is" resulted . resultedQ "`n ovalue is" Ovalue  )
      
      ;Xbug("going to set Ovalue with current ovalue = " ovalue " and result at " result)
      %assem% := Ovalue := (resulted .= resultedQ . resultedQS) ? com_invoke(Ovalue, result . resultisQ, regexreplace(resulted,"\Q#_\E","."))  : com_invoke(Ovalue, result)    
      ;%assem% := Ovalue := (resulted .= resultedQ . resultedQS) ? (result = "_") ? com_invoke(Ovalue,  regexreplace(resulted,"\Q#_\E",".")) : com_invoke(Ovalue, result . resultisQ, regexreplace(resulted,"\Q#_\E","."))  : com_invoke(Ovalue, result)
      
      ;debug( resulted ? "Ovalue, result, resulted, " Ovalue "," result "," resulted        : "")
      ;debug("assem" assem "`nresulted ? " resulted "`nOvalue , result"  Ovalue "," result)
      ;Xbug("set assem  on Ovalue <<-" Ovalue)
      
   
   }
   
   handle := %assem%
   
   return handle
         
}



; ---------------


old ver
Code:
ez_reinvoke( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe" )  {

return ez_invoke( object,  arg1,arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9,1 )

}

ez_invoke( object,  arg1="vT_NoNe",arg2="vT_NoNe",arg3="vT_NoNe",arg4="vT_NoNe",arg5="vT_NoNe",arg6="vT_NoNe",arg7="vT_NoNe",arg8="vT_NoNe",arg9="vT_NoNe", revoke = "" ) {

   if !object or ! ((instr(object,"+") ? regexmatch(object,"^\s*(?<object>[^+]+?)\.(?<obj>\+)(?<param>[\w=.]+)\s*$",_) : regexmatch(object,"^\s*(?<object>.+?)\.(?<param>[\w=]+)\s*$",_) ) )
   ;regexmatch(object,"^\s*(?<object>.+?)\.(?<obj>\+)?(?<param>[\w=]+)\s*$",_) )
      return
/*
   if ! object or !( pos := instr(object,".",0,0))
      return      
   param := substr(object,pos + 1)
   
   object := substr(object,1, pos - 1)
*/      
   if  ( _object != _object + 0 )
      _object := ez_invoke_findhandle(_object,revoke)
   
   
   if _obj {
   
      if  ( _param != _param + 0 )
         _param := ez_invoke_findhandle("#_" .  _param , revoke)

      _param := "+" . _param
   }
   
   return Com_Invoke(_object, _param , arg1 ,arg2 ,arg3,arg4,arg5,arg6,arg7,arg8,arg9)
   

}

ez_invoke_findhandle(object,revoke ="") {   

   global
   local myobject, handle, parts, resul, result, resulted, position, assem, value, Ovalue
   
   myobject := "#_" . regexreplace(object, "\.", "#_", parts)    
   ;Xbug( "my object is " myobject  "--> " %myobject%)
   
   
   if  ( (handle := %myobject%)  > 0 ) and (!revoke or !parts)
      return  handle

   position = 1
   loop {
      if !(position := regexmatch(myobject, "\#_(?<t>\w+)(?:\[(?<ted>\w+)\])?", resul,  position)
               + strlen(resul) )
         break
      
      assem .=  resul
      ;Xbug("assem is " assem )
      
      if (value := %assem%) and (!revoke or (a_index = 1) ) and (Ovalue := value) {
         ;Xbug( "value = assem ==> " value)
         continue
      
      }
      
      if !Ovalue
         return
/*
      if !Ovalue {
         if (a_index = 1) {
            value := substr(assem,3)
            if (Ovalue := %value%) > 0
               continue
         }
         
         return
      }   
*/
         
      ;Xbug("going to set Ovalue with current ovalue = " ovalue " and result at " result)
      %assem% := Ovalue := resulted ?  com_invoke(Ovalue, result, resulted)  : com_invoke(Ovalue, result)
         
      ;Xbug("set assem  on Ovalue <<-" Ovalue)
      
   
   }
   
   handle := %assem%
   
   return handle
         
}

; ©2007.  You can use this code only for your personal use, or if you publish your script source on this forum.
;  If you think this is a cool function,  keep in mind it's just a wrapper for Sean's *very* cool invoke()





example:

Code:
Speak(text, rate = "", voice# = "") {
   global
   static objVoice
   if !objVoice {

      com_init()

      objVoice := #_objVoice := com_CreateObject("SAPI.SpVoice")
   }
   
   if rate !=
      ez_invoke("objVoice.rate=",rate)

   if voice# !=
      ez_invoke("objVoice.Voice =+ objVoice.GetVoices[Name].Item",voice#) ; This number controls voice
      ;ez_invoke("objVoice.Voice=", "+" ez_invoke("objVoice.GetVoices[Name].Item",voice#)) ; This number controls voice

   if text !=
      ez_invoke("objVoice.Speak", text)
      
   return

}

_________________
Joyce Jamce


Last edited by Joy2DWorld on July 2nd, 2008, 11:45 pm, edited 20 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2007, 3:55 am 
Offline

Joined: November 12th, 2007, 4:46 am
Posts: 67
nice, although you should give more descrption, will add this to my library for when need it, i may even pu tit as a tool on my programing website.

_________________
online .ini reader with encryption

advanced tetris game many features


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2007, 3:58 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
if not clear above,


turns what used to need something like this:

Code:
pMM := com_invoke(pObjDoc,"MailMerge")
F3 := com_invoke(pMM, "Fields", "3")
pC := com_invoke(F3,"code")
text := com_invoke(pC,"Text")

--or--

text := com_invoke(com_invoke(com_invoke(com_invoke(pObjDoc,"MailMerge"), "Fields", "3")
,"code"),"Text")



into simply:


Code:
text := ez_invoke("objDoc.MailMerge.Fields[3].code.Text")

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2007, 8:26 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Nice!
Joy2DWorld wrote:
Code:
F3 := com_invoke(pMM, "Fields", "3")

I'd always assumed that it would not work, without actually trying it, which I always thought should be
Code:
F3 := COM_Invoke(COM_Invoke(pMM, "Fields"), "Item", 3)

(Actually, it should be invoked directly with DispID = 0.)
My bad...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 9th, 2007, 11:20 am 
Offline

Joined: May 24th, 2006, 2:49 pm
Posts: 4511
Location: Belgrade
Thx.

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2007, 9:33 am 
Offline

Joined: October 22nd, 2007, 3:44 pm
Posts: 11
Hm, can somebody post a working example of how this works. I tried the following:

Code:
COM_CoInitialize()
#_pweb := COM_Createobject("InternetExplorer.Application")
ez_Invoke("pweb.Visible=", "True")
ez_Invoke("pweb.Navigate", "http://www.mredkj.com/tutorials/tutorial005.html")

return


Based on the description in post 1, but that only gave me this error:

Quote:
---------------------------
test.ahk
---------------------------
Error: Call to nonexistent function.

Specifically: invoke(Ovalue, result, resulted) : invoke(Ovalue, result)

Line#
824: assem .= resul
827: if (value := %assem%) && (!revoke || (a_index = 1) ) && (Ovalue := value)
827: {
829: Continue
831: }
833: if !Ovalue
834: Return
---> 848: %assem% := Ovalue := resulted ? invoke(Ovalue, result, resulted) : invoke(Ovalue, result)
853: }
855: handle := %assem%
857: Return,handle
859: }
859: Exit

The program will exit.
---------------------------
OK
---------------------------


Thanks !

Edit: Just noticed this error comes up even if I don't use the ez_invoke functions. I just copied the functions to the bottom of my script, together with COM.ahk, do I have to #include it ? I wanted to avoid that, so I could easily use it with a batch file that contains something along the lines of:

Code:
@ECHO OFF
start .\Skript\Autohotkey.exe .\Skript\Test.ahk
exit


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 11th, 2007, 1:48 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
hotzenpl0tz wrote:
Hm, can somebody post a working example of how this works.


ahh... so much work and so little sleep......

you did everything right.


error was two " invoke(" that should have been " com_invoke("

script updated.



can just copy into ez.ahk in LIB directory, with Sean's com.ahk also in lib and run your script. No #Includes necessary.



hope this helps...

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 12th, 2007, 12:00 am 
Offline

Joined: July 16th, 2005, 11:39 am
Posts: 96
Many thanks! 8)
I will be much more comfortable with using COM now. After using Vba for
a while now, this syntax is more familiar to me.

_________________
“yields falsehood when preceded by its quotation” yields falsehood when preceded by its quotation.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 20th, 2007, 6:51 pm 
Hi, Joy2DWorld!
I found it very useful, thanks.
can you give a hand?
How can I express the code below with ez_invoke, or original com_invoke-way is ok.

Code:
objVoice.Voice = objVoice.GetVoices("Name=Microsoft Sam").Item(0)


[/code]


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 20th, 2007, 8:36 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
TTS Com wrote:
Hi, Joy2DWorld!
I found it very useful, thanks.
can you give a hand?
How can I express the code below with ez_invoke, or original com_invoke-way is ok.

Code:
objVoice.Voice = objVoice.GetVoices("Name=Microsoft Sam").Item(0)


[/code]


welcome!


just a guest,

step1: you need an object handle for objVoice

example:
Quote:
#_objVoice := com_CreateObject("**FILL IN HERE!:")

then perhaps ?


#_hMSsam := ez_com("objVoice.GetVoices.Name", "Microsoft Sam")

voice := ez_com("hMSsam.Item[0]")

ez_com("objVoice.Voice=", voice)





UNTESTED!! and just a guess!

remember, ez_com is encapsulating VB OBJECTS, not VB code,

so you have to unwrap the VB code and deal with each discreet object as it's own encapsulation, eg:

ez_com("objVoice.Voice=", ez_com("hMSsam.Item[0]"))

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 20th, 2007, 10:18 pm 
Code:

vbcode=
(
Set objVoice = CreateObject("SAPI.SpVoice")
objVoice.rate = 1

Set objVoice.Voice = objVoice.GetVoices("Name=VW Kate").Item(0)
objVoice.Speak "Thank you, Joy2DWorld!"

Set objVoice.Voice = objVoice.GetVoices("Name=VW Paul").Item(0)
objVoice.Speak "But I can't get it to work, and settled with this script embedding method. Thoug I have to createobject everytime.Thanks again."
)

Com_ScriptControl(vbcode, "VBscript")



Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2007, 3:36 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
TTS Com wrote:
How can I express the code below with ez_invoke, or original com_invoke-way is ok.
Code:
objVoice.Voice = objVoice.GetVoices("Name=Microsoft Sam").Item(0)

The COM_Invoke() way may be:
Code:
COM_Invoke(objVoice, "Voice=", "+" . COM_Invoke(COM_Invoke(objVoice, "GetVoices", "Name=Microsoft Sam"), "Item", 0))

PS. Added missing "+".


Last edited by Sean on December 21st, 2007, 11:25 am, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 21st, 2007, 6:08 am 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
try this...


Code:
com_init()

#_objVoice := com_CreateObject("SAPI.SpVoice")

ez_invoke("objVoice.rate=",6)

ez_invoke("objVoice.Voice=", "+" ez_invoke("objVoice.GetVoices[Name].Item",2)) ; This number controls voice

ez_invoke("objVoice.Speak", "Thank you, Joy2DWorld!" )





Code:

speak("kind of `;; cool!!",2,2)
return

Speak(text, rate = "", voice# = "") {
   global
   static objVoice
   if !objVoice {

      com_init()

      objVoice := #_objVoice := com_CreateObject("SAPI.SpVoice")
   }
   
   if rate !=
      ez_invoke("objVoice.rate=",rate)

   if voice# !=
      ez_invoke("objVoice.Voice=", "+" ez_invoke("objVoice.GetVoices[Name].Item",voice#)) ; This number controls voice

   if text !=
      ez_invoke("objVoice.Speak", text)
      

}

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 25th, 2007, 4:44 pm 
To Sean and Joy2DWorld.

I really need your help.

Below is working script.

But I don't wanna depend on VBcode 'cause once vbscript is excuted, I can't use the object created within vbstring again and further I can't put object created in ahkscript into vbscript(Am I right?)

Code:
com_init()

filedir = %A_mydocuments%\TTS_Sample.wav

vbcode=
(
Set objVoice = CreateObject("SAPI.SpVoice")
Set objVoice.Voice = objVoice.GetVoices("Name=Microsoft Sam").Item(0)


'to save speech into wave file form

set spFilestream = Createobject("SAPI.SpFileStream")
spFileStream.Format.Type = 22
spFileStream.Open "%filedir%", 3, False
Set objVoice.AudioOutputStream = spFileStream

objVoice.Speak "My name is Sam."

spFileStream.close
Set spFileStream = Nothing
Set objVoice.AudioOutputStream = Nothing
)

Com_ScriptControl(vbcode, "VBscript")

It working corret.
It doesn't speak but save speech to wav file.

so, I translated above script to

Code:
com_init()
filedir = %A_mydocuments%\tts_sample.wav

objVoice := Com_CreateObject("SAPI.SpVoice")
COM_Invoke(objVoice, "Voice=", "+" . COM_Invoke(COM_Invoke(objVoice, "GetVoices", "Name=Microsoft Sam"), "Item", 0))

spFileStream := Com_createObject("SAPI.SpFileStream")
Com_Invoke(Com_Invoke(spFileStream, "Format"), "Type=", 22)
Com_Invoke(spFileStream, "Open", filedir, 3, False)
Com_invoke(objVoice, "AudioOutputStream=", spFileStream) <--- I guess this part is not working
COM_Invoke(objVoice, "Speak", "My name is Sam!")


It speaks "My name is Sam!"
I mean, instead of speaking, it should have written speech to wav file.

Com_invoke(objVoice, "AudioOutputStream=", spFileStream)
<--- this part is not working, I guessed

Is there something I should know?
Because I don't understand "Set Property" in both(Sean's and Joy2DWorld's) script.

Sean's script

COM_Invoke(objVoice, "Voice=", "+" . COM_Invoke(COM_Invoke(objVoice, "GetVoices", "Name=Microsoft Sam"), "Item", 0))


From where and why does "plus sign(+)" shoudl be there?
why not below line?

COM_Invoke(objVoice, "Voice=", COM_Invoke(COM_Invoke(objVoice, "GetVoices", "Name=Microsoft Sam"), "Item", 0))



and Joy2DWorld's is the same. What the heck is that plus sign?

I always thought

set objvoice.voice = something

should be rewritten to

com_invoke(objvoice, "voice=", something)?

I am very, very confused.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: December 25th, 2007, 7:26 pm 
Offline

Joined: December 4th, 2006, 10:35 am
Posts: 561
Location: Galil, Israel
"+" used in Sean's invoke (and, since it's just wrapping Sean's invoke, the ez_invoke) designates an object handle.


ie. "this = 12" ==> "this",12

but "this=object.two" ==> "this", "+" ez_invoke("object.two")

_________________
Joyce Jamce


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 82 posts ]  Go to page 1, 2, 3, 4, 5, 6  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Klark92 and 33 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group