Jump to content
Sign in to follow this  
Eemuli

AutoItObject - How to use .Create() ?

Recommended Posts

I am using

I have created an object and I would like other object to inherit the first one. Here is the code:

#include "AutoitObject.au3"
Opt("MustDeclareVars", 1)

; Error monitoring
Global $oError = ObjEvent("AutoIt.Error", "_ErrFunc")

; Initialize AutoItObject
_AutoItObject_StartUp()

; Create Object
Global $oObject = _SomeObject()
Global $oClone = _cloneObject()

; Set some property
$oObject.Title = "Hey"

;Display messagebox
$oObject.MsgBox("Test")

$oClone.Title = "Cloned"
$oClone.MsgBox("Clone object")

; Relese
$oObject = 0 ; <-!Comment this out to see the new behavior!

; That's it! Goodby



; Define object
Func _SomeObject()
    Local $oClassObject = _AutoItObject_Class()
    $oClassObject.Create()
    $oClassObject.AddMethod("MsgBox", "_Obj_MsgBox")
    $oClassObject.AddProperty("Title", $ELSCOPE_PUBLIC, "Something")
    $oClassObject.AddProperty("Text", $ELSCOPE_PUBLIC, "Some text")
    $oClassObject.AddProperty("Flag", $ELSCOPE_PUBLIC, 64 + 262144)
    $oClassObject.AddDestructor("_DestructorForSomeObject")
    Return $oClassObject.Object
EndFunc   ;==>_SomeObject

Func _Obj_MsgBox($oSelf, $string)
    MsgBox($oSelf.Flag, $oSelf.Title, $string)
EndFunc   ;==>_Obj_MsgBox

Func _DestructorForSomeObject($oSelf)
    ConsoleWrite("!...destructing..." & @CRLF)
EndFunc

Func _ErrFunc()
    ConsoleWrite("! COM Error !  Number: 0x" & Hex($oError.number, 8) & "   ScriptLine: " & $oError.scriptline & " - " & $oError.windescription & @CRLF)
    Return
EndFunc   ;==>_ErrFunc

Func _cloneObject()
    Local $oClass = _AutoItObject_Class()

    With $oClass
        .Create($oObject)
    EndWith

    Return $oClass.Object
EndFunc

For some reason $oClone doesnt inherit $oObject. Code returns "! COM Error ! Number: 0x8002000E ScriptLine: 59 - Invalid number of parameters." (Line 59 = .Create($oObject))

even though in help file it says that $oParent parameter can be given for .Create() method. => "Create([$oParent = 0]) - creates AutoItObject object"

I know I can use _AutoItObject_Create($oObject) and that one works fine, but why doesnt .Create($oObject) ?

Am I doing something wrong?

Im using AutoIt version v3.3.8.0 and

AutoItObject UDF version v1.2.8.2.

Share this post


Link to post
Share on other sites

Use _AutoItObject_AddMethod() and ...AddProperty() in the class which inherits from another class.

For instance, if you have a class which defines some methods and you want another class to inherit those methods. So, class_one() defines a method and class_two() wants to use that method then put Local $this = class_one()) inside of class_two().

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include "AutoitObject.au3"

_AutoItObject_StartUp()

Global $concrete = concrete_class()

$concrete.HelloWorld()

$concrete.HelloWorldAgain()

$concrete = ''

_AutoItObject_Shutdown()

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

Func abstract_class()
    Local $this = _AutoItObject_Class()
    $this.AddMethod("HelloWorld", "abstract_hello_world")
    $this.AddDestructor("abstract_dtor")
    Return $this.Object
EndFunc

Func abstract_dtor(Const $this)
    MsgBox(0, "Abstract", "Destructed")
    Return $this
EndFunc

Func abstract_hello_world(Const $this)
    MsgBox(0, "Abstract", "Hello World")
    Return $this
EndFunc

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

Func concrete_class()
    Local $this = abstract_class()
    _AutoItObject_AddMethod($this, "HelloWorldAgain", "concrete_hello_world_again")
    _AutoItObject_AddDestructor($this, "concrete_dtor")
    Return $this
EndFunc

Func concrete_dtor(Const $this)
    MsgBox(0, "Concrete", "Destructed")
    Return $this
EndFunc

Func concrete_hello_world_again(Const $this)
    MsgBox(0, "Concrete", "Hello World Again")
    Return $this
EndFunc

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

Heavily edited due to giving totally wrong answer first few times around.

Edited by LaCastiglione

Share this post


Link to post
Share on other sites

Use _AutoItObject_AddMethod() and ...AddProperty() in the class which inherits from another class.

For instance, if you have a class which defines some methods and you want another class to inherit those methods. So, class_one() defines a method and class_two() wants to use that method then put Local $this = class_one()) inside of class_two().

Indeed, that is working and you can also do it like this:

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include "AutoitObject.au3"

_AutoItObject_StartUp()

Global $abstract = abstract_class()
Global $concrete = concrete_class()

$concrete.HelloWorld()

$concrete.HelloWorldAgain()

$concrete = ''

_AutoItObject_Shutdown()

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

Func abstract_class()
    Local $this = _AutoItObject_Class()
    $this.AddMethod("HelloWorld", "abstract_hello_world")
    $this.AddDestructor("abstract_dtor")
    Return $this.Object
EndFunc

Func abstract_dtor(Const $this)
    MsgBox(0, "Abstract", "Destructed")
    Return $this
EndFunc

Func abstract_hello_world(Const $this)
    MsgBox(0, "Abstract", "Hello World")
    Return $this
EndFunc

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

Func concrete_class()
    Local $this = _AutoItObject_Create($abstract)
    _AutoItObject_AddMethod($this, "HelloWorldAgain", "concrete_hello_world_again")
    _AutoItObject_AddDestructor($this, "concrete_dtor")
    Return $this
EndFunc

Func concrete_dtor(Const $this)
    MsgBox(0, "Concrete", "Destructed")
    Return $this
EndFunc

Func concrete_hello_world_again(Const $this)
    MsgBox(0, "Concrete", "Hello World Again")
    Return $this
EndFunc

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

But now the question remains - why cant it be done like this:

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include "AutoitObject.au3"

_AutoItObject_StartUp()

Global $abstract = abstract_class()
Global $concrete = concrete_class()

$concrete.HelloWorld()

$concrete.HelloWorldAgain()

$concrete = ''

_AutoItObject_Shutdown()

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

Func abstract_class()
    Local $this = _AutoItObject_Class()
    $this.AddMethod("HelloWorld", "abstract_hello_world")
    $this.AddDestructor("abstract_dtor")
    Return $this.Object
EndFunc

Func abstract_dtor(Const $this)
    MsgBox(0, "Abstract", "Destructed")
    Return $this
EndFunc

Func abstract_hello_world(Const $this)
    MsgBox(0, "Abstract", "Hello World")
    Return $this
EndFunc

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

Func concrete_class()
    Local $this = _AutoItObject_Class()
    $this.Create($abstract)
    $this.AddMethod($this, "HelloWorldAgain", "concrete_hello_world_again")
    $this.AddDestructor($this, "concrete_dtor")
    Return $this.Object
EndFunc

Func concrete_dtor(Const $this)
    MsgBox(0, "Concrete", "Destructed")
    Return $this
EndFunc

Func concrete_hello_world_again(Const $this)
    MsgBox(0, "Concrete", "Hello World Again")
    Return $this
EndFunc

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

According to the help file both ways presented above should be correct. Only problem is that you cant use any parameters with "$this.create()" method.

Does above scripts work on your computer?

[EDIT] Some syntax errors in code.

Edited by Eemuli

Share this post


Link to post
Share on other sites

I would file a bug report over at the AIO project page.

Indeed, that is working and you can also do it like this:

Indeed. This does work. However, for me it calls the dtor for abstract twice.

According to the help file both ways presented above should be correct. Only problem is that you cant use any parameters with "$this.create()" method. Does above scripts work on your computer?

Just fix up your syntax if you decide to use your second example...

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include "AutoitObject.au3"

_AutoItObject_StartUp()

Global $abstract = abstract_class()
Global $concrete = concrete_class()

$concrete.HelloWorld()

$concrete.HelloWorldAgain()

$concrete = ''

_AutoItObject_Shutdown()

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

Func abstract_class()
    Local $this = _AutoItObject_Class()
    $this.AddMethod("HelloWorld", "abstract_hello_world")
    $this.AddDestructor("abstract_dtor")
    Return $this.Object
EndFunc

Func abstract_dtor(Const $this)
    MsgBox(0, "Abstract", "Destructed")
    Return $this
EndFunc

Func abstract_hello_world(Const $this)
    MsgBox(0, "Abstract", "Hello World")
    Return $this
EndFunc

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

Func concrete_class()
    Local $this = _AutoItObject_Class()
    $this.Create($abstract)
    $this.AddMethod("HelloWorldAgain", "concrete_hello_world_again")
    $this.AddDestructor("concrete_dtor")
    Return $this.Object
EndFunc

Func concrete_dtor(Const $this)
    MsgBox(0, "Concrete", "Destructed")
    Return $this
EndFunc

Func concrete_hello_world_again(Const $this)
    MsgBox(0, "Concrete", "Hello World Again")
    Return $this
EndFunc

; -------------------------------------------------------------------------------------------------
Edited by LaCastiglione

Share this post


Link to post
Share on other sites

Hi,

I have the same problem on Win Xp,

i have show your post on http://autoitobject.origo.ethz.ch/issues

So for me, the way is to redefine the "_AutoItObject_Class()" fonction

I have write a customized _AutoItObject_Class with oParent parameter :

;================================================================================================
; Customized Class Object
;=====================================================================================================
Func _AutoitObj_Class($oParent)
Local $oThis = _AutoItObject_Create()
_AutoItObject_AddMethod($oThis, "AddProperty", "_Object_AddProperty")
_AutoItObject_AddMethod($oThis, "AddMethod", "_Object_AddMethod")
_AutoItObject_AddMethod($oThis, "Create", "_Object_Create")
_AutoItObject_AddProperty($oThis, "Object", $ELSCOPE_PUBLIC, 0)
_AutoItObject_AddProperty($oThis, "Parent", $ELSCOPE_PUBLIC, $oParent)
Return $oThis
EndFunc

and the customized fonction :

Func _Object_Create($oSelf)
$oSelf.Object = _AutoItObject_Create($oSelf.Parent)
EndFunc
Func _Object_AddMethod($oSelf, $Name, $Fonction)

Local $oObject = $oSelf.Object
_AutoItObject_AddMethod($oObject, $Name, $Fonction)
EndFunc
Func _Object_AddProperty($oSelf, $Name, $Scope, $Value)
Local $oObject = $oSelf.Object
_AutoItObject_AddProperty($oObject, $Name, $Scope, $Value)
EndFunc

For use it you just have to :

Global $oMyObject = _MyObject()
$oMyObject.MyMethod

Func _MyObject($oParent=0)
Local $oClass = _AutoitObj_Class($oParent)
$oClass.Create
$oClass.AddProperty("MyProperty", $ELSCOPE_PUBLIC, 4)
$oClass.AddMethod("MyMethod", "testMyMethod")
Return $oClass.Object
EndFunc
Func testMyMethod($oSelf)
MsgBox(0, "", "MyProperty = "&$oSelf.MyProperty)
EndFunc

FOR ME IT WORK with Parameter $oParent

If you have suggestion for the code please post it

Share this post


Link to post
Share on other sites

Sorry,

i correct some mistake

So for me, the way is to redefine the "_AutoItObject_Class()" fonction

I have write a customized _AutoItObject_Class with oParent parameter :

;================================================================================================
; Customized Class Object
;=====================================================================================================
Func _AutoitObj_Class($oParent)
Local $oCustom = _AutoItObject_Create()
      _AutoItObject_AddMethod($oCustom, "AddProperty", "_Object_AddProperty")
      _AutoItObject_AddMethod($oCustom, "AddMethod", "_Object_AddMethod")
      _AutoItObject_AddMethod($oCustom, "Create", "_Object_Create")
      _AutoItObject_AddProperty($oCustom, "Object", $ELSCOPE_PUBLIC, 0)
      _AutoItObject_AddProperty($oCustom, "Parent", $ELSCOPE_PUBLIC, $oParent)
Return $oCustom
EndFunc

and the customized fonction :

;=================================================================================
; Customized Fonction Create - Class Object
;=======================================================================================Func _Object_Create($oSelf)
     $oSelf.Object = _AutoItObject_Create($oSelf.Parent)
EndFunc

;=======================================================================================
; Customized Fonction AddMethod - Class Object
;=======================================================================================
Func _Object_AddMethod($oSelf, $Name, $Fonction)
     Local $oObject = $oSelf.Object
     _AutoItObject_AddMethod($oObject, $Name, $Fonction)
EndFunc


;======================================================================================
; Customized Fonction AddProperty - Class Object
;=======================================================================================
Func _Object_AddProperty($oSelf, $Name, $Scope, $Value)
     Local $oObject = $oSelf.Object
     _AutoItObject_AddProperty($oObject, $Name, $Scope, $Value)
EndFunc

Example For use it you just have to :

#include <AutoItObject.au3>
Global $oParent
_AutoItObject_Startup()

;// Obj 1
Global $oMyObject1 = _AutoItObject_Create()
_AutoItObject_AddProperty($oMyObject1, "MyProperty_Obj1", $ELSCOPE_PUBLIC, "Object 1")

;// Obj 2 with parent Obj 1
Global $oMyObject2 = _MyObject($oMyObject1)
$oMyObject2.MyMethod

;// Class definition Obj 2
Func _MyObject($oParent=0)
Local $oClass = _AutoitObj_Class($oParent)
$oClass.Create
$oClass.AddProperty("MyProperty_Obj2", $ELSCOPE_PUBLIC, "Object 2")
$oClass.AddMethod("MyMethod", "testMyMethod")
$oCustom = 0 ; delete the custom object
Return $oClass.Object
EndFunc

;// Methode obj 2
Func testMyMethod($oSelf)
MsgBox(0, "", "MyProperty_Obj1 = "&$oSelf.MyProperty_Obj1 &@CRLF& _
"MyProperty_Obj2 = "&$oSelf.MyProperty_Obj2 )
EndFunc

FOR ME IT WORK with Parameter $oParent

If you have suggestion for the code please post it

Edited by M2C

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By SEuBo
      Hi there,
      while I created an example script to generate and execute a function during runtime, I stumbled across a neat way to share data between running autoit scripts.
      This is done using the amazing magic of AutoItObject and  AutoItObject_Internal . (You'll need both UDF's) (You'll need at least Version 3.0.0 of AutoItObject_Internal)
      Using this UDF, you can create a shared data storage, a simple AutoItObject-Object, and thanks to AutoItObject_Internal a simple AutoItObject_Internal-Object which you can then use to write / read data Inline. no set/get methods, just
      #include "AutoItSharedData.au3" $oShare = _AutoIt_SharedData_CreateOrAttach("MyCustomID") $oShare.some_data = 'foo' and you're done. any other script accessing this data will have to do:
      #include "AutoItSharedData.au3" $oShare = _AutoIt_SharedData_CreateOrAttach("MyCustomID") ConsoleWrite($oShare.some_data & @LF)  
      Basically it's Larsj's Implementing IRunningObjectTable Interface, but you dont have a Dictionary, but an IDIspatch Object instead.
      There are already a bunch of IPC options available - and this is another one.
      AutoItSharedData.au3
       
      Example Script 1
       
      Example Script 2
      Output: 
      To test: run Example Script 1, Then run example Script 2.. or the other way around.
      Example Script 3
      Example_sharedata3.au3
      Example_sharedata3_Controlsend.au3
      Example_sharedata3_Tooltip.au3
      To test: run Example_sharedata3.au3.
      Output: 
       
       Example SharedData4:
      Output: 
      /Edit: Please note that there's a limitation with the Running object table :
      The Script accessing a variable first, will be the "server" for this variable. This means, access to that variable from other scripts should only be possible, as long the "server" script is running! Use appropriate Object Error handlers in case you don't want the surviving "clients" to crash.
      Feedback and/or improvements appreciated
       
      changelog
      version 2.0
      Removed need for AutoItObject, as AutoItObject_Internal now comes with ROT support Added UDF Header Fixed typo on "#include AutoItObjectInternal.au3" -> "#include AutoItObject_Internal.au3" Added ObjGet() after registering the object fails (in case 2 programs tried to register the same ID simultaneously) Updated Examples & zip archive. Cheers,
       
      AutoItSharedData.zip
    • By genius257
      First of all I've been searching on the forum, and while there's been done something like this with: https://www.autoitscript.com/forum/topic/141004-comobject-proxy-seamless-windows-script-control-autoitobj/
      I could not find any solution to my predicament.
       
      Is it possible to throw an error in a ScriptControl object, via AutoIt?
      I have a script, where AutoIt calls ScriptControl:JavaScript which in turn calls AutoIt.
      However i would like to be able to make AutoIt invoke an exception within ScriptControl, if the called functionality fails.
      Here's some code for reference:
      #AutoIt3Wrapper_Run_AU3Check=n #include-once #include "AutoitObject.au3" #include <WinAPIDiag.au3> $oJS = ObjCreate("ScriptControl") $oJS.Language = "JScript" $oJS.TimeOut = 0; A value of 0 means that the ScriptControl will monitor the execution of the script and will trigger the Timeout event if it determines that the script is hung. _AutoItObject_Startup() $oAutoIt = _AutoItObject_Create() _AutoItObject_AddMethod($oAutoIt, "Execute", "_Execute", False) $oJS.AddObject("AutoIt", $oAutoIt, True) OnAutoItExitRegister("_CleanUp") $_AutoItError = ObjEvent("AutoIt.Error", "_AutoItError") Func _CleanUp() ConsoleWrite("Cleaning up..."&@CRLF) $oJS = 0 $oAutoIt = 0 _AutoItObject_Shutdown() EndFunc Func _Execute($oSelf, $sString) $vReturn = Execute($sString) If @error<>0 Then Return $oJS.Eval("throw new SyntaxError();"); Does invoke exception, but not within the try/catch Return $vReturn EndFunc Func _AutoItError($oError) $oError2 = $oJS.Error ConsoleWrite( _ "Column: " & $oError2.Column & @CRLF & _ "Description: " & $oError2.Description & @CRLF & _ "HelpContext: " & $oError2.HelpContext & @CRLF & _ "HelpFile: " & $oError2.HelpFile & @CRLF & _ "Line: " & $oError2.Line & @CRLF & _ "Number: " & $oError2.Number & @CRLF & _ "Source: " & $oError2.Source & @CRLF & _ "Text: " & $oError2.Text & @CRLF _ ) $oError2.Clear() EndFunc $oJS.Eval("(function(){"& _ "try{"& _ "AutoIt.Execute('MsgBox(0,\'\', \'a\')');"& _ "AutoIt.Execute('a.b');/*error should occur here*/"& _ "AutoIt.Execute('MsgBox(0,\'\', \'b\')');"& _ "}catch(e){"& _ "AutoIt.Execute('ConsoleWrite(\'Error\'&@CRLF)');"& _ "}"& _ "})()")  
    • By tarretarretarre
      Now its my turn to give back to the community ( Better late than never :P)..
       
      First i want to thank progAndy for his amazing UDF which this idea came from

       
      And the AutoitObject Team (For making autoit fun again)
       

      I dont have so much to say more thant to let the project speak for itself, ive had this for a couple of months but it was "integrated" into my own "framework" but today I decided to release it because i have seen some people on the forum search for something like this.
      What libraries does this use and are they included?
      Connector/C 6.1.6 ( https://dev.mysql.com/downloads/connector/c/ ) And yes, they are included in the download so nothing has to be installed or anything

      What are the features:
      Prepared statements 32 and 64 bit environment Multiline prepared statements  Simplicity User-friendly PDO-like Syntax & Methods (http://php.net/pdo)  
      So whats the difference between this and x's Mysql UDF?
      When you are fetching your data from your database, you use your table-names to display them, like this:
      with $MySql Local $Vars = ["?", $lastname, "?", $age] .prepare("SELECT id, surname, lastname FROM users WHERE lastname = ? AND AGE > ?") .execute($Vars) Consolewrite(stringformat("Searchresult: %d Hits", .rowCount()) for $row in $oRows consolewrite("Surname: " & $row.surname & @crlf) consolewrite("Lastname: " & $row.lastname & @crlf) next endwith  
      Function-list (Yeah i might improve this when i have time)
      ; Every parameter is a default value of method _miniSQL_setDllDir(@ScriptDir); returns nothing Local Const $MySql = _miniSQL_LoadLibrary(); Returns object with methods ; Starts the library, connects to the database and returns the object $MySql.Startup($sHost, $sUser, $sPass = "", $sDatabase = "", $iPort = 0, $sUnix_socket = "", $iClient_Flag = 0); Returns TRUE if connection was succeded otherwise FALSE ; Shuts down the library and prevents any methods to be executed $MySql.Shutdown() ; The desired SQL query goes here (SELECT x FROM table) $MySql.prepare($sQuery); Returns nothing ; Used for multi-line prepared statements (See Example3 - newline prepared statements) $MySql.PrepareGlue($sQuery); Returns nothing ; Cleans any previous prepared statement of any kind $MySql.PrepareClean(); Returns nothing ; Executes a prepared statement of any kind, with or without passed arguments $MySql.execute($aVars = Null, $iExecuteStyle = $_miniSQL_ExecuteStoreResult); returns TRUE if success, otherwise FALSE ; Options for $iExecuteStyle: $_miniSQL_ExecuteStoreResult = 0 and $_miniSQL_ExecuteOnly = 1 ; Fetches previous executed prepared statement (If anything was stored "see Options for iExecuteStyle") $MySql.fetchAll($iFetchStyle = $_miniSQL_FetchObject); Returns (Depends on $iFetchStyle) ; Options for $iFetchStyle: $_miniSQL_FetchObject = 0 (Default), $_miniSQL_FetchSingleObject = 1, $_miniSQL_FetchArray = 2, $_miniSQL_FetchSingleValue = 3 ; Gives you the "lastinsertId" (The last id that was affected) $MySql.lastInsertId(); Returns the last affected id ; Counts the affected rows done by any MySQL operation (INSERT\SELECT\UPDATE\DELETE) $MySql.rowCount(); Returns how affected rows ; Use this if want to know why nothing is working (Can be used anywhere after $MySql.Startup()) $MySql.debug(); Returns nothing ; Retrives the last MysqlError set $MySql.SQLerror(); Returns error (If any) Here is some example code:
      #include <miniSQL\miniSQL.au3> ; Set default dir for our dlls (Only has to be done once) _miniSQL_setDllDir(@ScriptDir & "\miniSQL") ; Declared as CONST since we never want to accidentally change the variables original value Local Const $MySql = _miniSQL_LoadLibrary() ;Connect to database & Init library If Not $MySql.Startup("localhost", "user", "pass", "db", 3306) Then MsgBox(0, "Failed to start library", $MySql.debug()) Exit EndIf With $MySql .prepare("SELECT * FROM members") If Not .execute() Then MsgBox(0, "Failed to execute query", .sqlError()) Local $oRows = .fetchAll() ; Print how many rows got affected by latest query ConsoleWrite(StringFormat("Number of rows to display: %s", .rowCount()) & @CRLF) ; we use isObj to check if we got any result. If IsObj($oRows) Then For $row In $oRows ConsoleWrite(StringFormat("Id: %s", $row.id) & @CRLF) ConsoleWrite(StringFormat("Name: %s", $row.name) & @CRLF) ConsoleWrite(StringFormat("Bio: %s", $row.bio) & @CRLF) Next Else ConsoleWrite("No rows to show"&@CRLF) EndIf EndWith ; Use this in your app when you are done using the database $MySql.Shutdown() #include <miniSQL\miniSQL.au3> ; Set default dir for our dlls (Only has to be done once) _miniSQL_setDllDir(@ScriptDir & "\miniSQL") ; Declared as CONST since we never want to accidentally change the variables original value Local Const $MySql = _miniSQL_LoadLibrary() ;Connect to database & Init library If Not $MySql.Startup("localhost", "user", "pass", "db", 3306) Then MsgBox(0, "Failed to start library", $MySql.debug()) Exit EndIf With $MySql ; We use an array to make our query look nicer Local $vars = [":name", @UserName&Random(1,10,1)] ; Prepare our statement .prepare("UPDATE members SET name = :name WHERE 1") If Not .execute($vars) Then MsgBox(0, "Failed to execute query", .sqlError()) ; Print how many rows got affected by latest query ConsoleWrite(StringFormat("Example 1 rows affected: %s", .rowCount()) & @CRLF) EndWith ; We can also prepare like this With $MySql Local $vars = ["?", @UserName, "?", 1] ; Prepare our statement .prepare("UPDATE members SET name = ? WHERE id = ?") If Not .execute($vars) Then MsgBox(0, "Failed to execute query", .sqlError()) ; Print how many rows got affected by latest query ConsoleWrite(StringFormat("Example 2 rows affected: %s", .rowCount()) & @CRLF) EndWith ; Use this in your app when you are done using the database $MySql.Shutdown()  
      With $MySql ; We use an array to make our query look nicer Local $vars = ["?", 1] ;Line by line prepared statement .prepareClean(); .prepareGlue("SELECT *") .prepareGlue("FROM members") .prepareGlue("WHERE id = ?") If Not .execute($vars) Then MsgBox(0, "Failed to execute query", .sqlError()) ; Print how many rows got affected by latest query ConsoleWrite(StringFormat("Example 1 rows affected: %s", .rowCount()) & @CRLF) EndWith ; Use this in your app when you are done using the database $MySql.Shutdown() Some code from one of my applications at work using this UDF
      With $MySql .prepareClean() .prepareGlue("SELECT") .prepareGlue("cases.cases_dedu_casenumber,") .prepareGlue("cases.cases_created_by_ugid,") .prepareGlue("cases.cases_dedu_ftg,") .prepareGlue("cases.cases_date_created,") .prepareGlue("cases.cases_date_finished,") .prepareGlue("cases.cases_protocol_director,") .prepareGlue("cases.cases_finished_by_ugid,") .prepareGlue("IFNULL(uid1.names_name, 'none') as createdByFullname,") .prepareGlue("IFNULL(uid2.names_name, 'none') as finishedByFullname") .prepareGlue("FROM cases") .prepareGlue("LEFT JOIN names AS uid1") .prepareGlue("ON cases.cases_created_by_ugid = uid1.names_uid") .prepareGlue("LEFT JOIN names AS uid2") .prepareGlue("ON cases.cases_finished_by_ugid = uid2.names_uid") if $_App_Case_SearchFor Then .prepareGlue(StringFormat("WHERE cases_dedu_casenumber LIKE '%s'",$_App_Case_SearchFor)) .prepareGlue("ORDER BY cases.cases_date_created DESC") .prepareGlue("LIMIT 0, 30") if not .execute() then return __ThrowException(.sqlError()) Local $oRows = .fetchAll() EndWith  
       
      Git: https://gitlab.com/xdtarrexd/MiniSQL.git
      Download: Zip generated from Github
       
      Feel free to open your mind about this
    • By therms
      If you don't like dealing with Scripting.dictionary you might want to try out this thing I whipped up yesterday evening and this morning.
      Basically just a simple wrapper around Scripting.dictionary to make the API a little bit less stupid.  By "stupid" I mean "not like the awesome Python dict API".
      Created for the following reasons..
      Wanted to get a basic understanding of AutoItObject. Wanted to get a basic understanding of the Micro unit test framework. As of 11/4/2014 AutoIt Stable has no native dict or associative array type.  A >Map type is in the current AutoIt beta. It's laborious to use Scripting.dictionary all the time. The Python dict API is better than Scripting.dictionary's I thought about writing my own hash table implementation in AutoIt, but on balance I decided it wasn't worth the effort and just stuck to Scripting.dictionary to save time/effort.
      As you can see I've got a decent number of unit tests for such a simple implementation, so it should be quite robust.
      #include <Dict2.au3> #include <Array.au3> $dict = _DictCreate() ConsoleWrite($dict.len()) ; Outputs 0 $dict.set("key1", "value1") $dict.set("key2", "value2") $dict.set("key3", "value3") $dict.set("key4", 1) ConsoleWrite($dict.get("key2")) ; Outputs 'value2' ConsoleWrite($dict.len()) ; Outputs 3 ConsoleWrite($dict.contains("key2") ; Outputs True $dict.set("key4", $dict.get("key4") + 1) ConsoleWrite($dict.get("key4")) ; Outputs 2 $dict.del("key4") ConsoleWrite($dict.contains("key4")) ; Outputs False $aPairs = $dict.pairs() _ArrayDisplay($aPairs) ; Displays 2d array with column one contains keys, and column two ; containing associated values $aKeys = $dict.keys() _ArrayDisplay($aKeys) ; Displays array containing all keys $aValues = $dict.values() _ArrayDisplay($aValues) ; Displays array of all values $aDesiredKeys = ["key1", "key3"] $aValues = $dict.values($aDesiredKeys) _ArrayDisplay($aValues) ; Displays array of values for key1 and key3 GET IT HERE
    • By SirJohann
      Hi guys, I've been working with AutoItObject and I'm curious about a thing.
      This code:
      #include 'AutoItObject.au3' _AutoItObject_Startup() Global $_oBasicObject = _AutoItObject_Create() _AutoItObject_AddProperty($_oBasicObject, 'prop', $ELSCOPE_PUBLIC, _AutoItObject_Create($_oBasicObject)) Ok, when you use _AutoItObject_Create you can copy all the properties from another object, but now he is copying himself, so the value of $_oBasicObject.prop will be another object with an exact property and is a loop or what? Then $_oBasicObject.prop.prop.prop is another object with another prop?
×
×
  • Create New...