Jump to content

Problem with WM_COMMAND and Arrays


Go to solution Solved by j0kky,

Recommended Posts

Hello,

I'm using AutoIT v 3.3.10.2. Hopefully this version is late enough. I just checked for updates and saw the new 3.3.12.0. But I don't think that will solve my issue.

The problem I'm having is that when I'm handling an array used in a WM_COMMAND function AutoIT just stops responding.

Hopefully the code below is enough to understand the problem. Both _ArrayDisplay($arr_earlier_errands_2) and _showMyErrandsGUI($arr_earlier_errands) arrayfunctions makes AutoIT tonot respond. If I use the exact same code outside the function "_WM_COMMAND_FUNC" it will work properly. I'm using my SQL-functions all over the script without any problem. But at this point it just won't work. I'm starting to get frustrated. :)

Anyone have a sollution?

Thanks!

Max Edman

GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND_FUNC")
Global $input_mobilenumber = GUICtrlCreateInput("", 216, 139, 201, 26, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NUMBER))




Func _WM_COMMAND_FUNC($hwnd_main, $imsg, $iwParam, $ilParam)
    Local $setHK = False
    Local $nNotifyCode = BitShift($iwParam, 16)
    Local $nID = BitAND($iwParam, 0x0000FFFF)
    Local $hwnd_GUICtrl = $ilParam

;~  ; Hanterar enbart de meddelanden
    If $nNotifyCode = $EN_CHANGE Then
        If $hwnd_GUICtrl = GUICtrlGetHandle($input_mobilenumber) Then
            Local $s_mobile_number = GUICtrlRead($input_mobilenumber)
            If StringRegExp($s_mobile_number, "\A(07[0-9]{8})") And StringLen($s_mobile_number) = 10 Then
;~  ; Om värdet för mobilnummer uppfyller kraven för hur ett mobilnummer ser ut så söks detta igenom i databasen.
                Local $obj_SQL_conn = _SQL_connect_Automate_Levstat()
                Local $i_number_of_records = _SQLCountRows($obj_SQL_conn, "*tableName*", "*colName", $s_mobile_number)
;~  ; Hittas inga ärenden på detta mobilnummer så returneras 1 direkt.
                If $i_number_of_records = 0 Then
                    _SQLDisconnect($obj_SQL_conn)
                    Return 1
;~  ; Annars ställs frågan om användaren vill se dessa ärenden.
                ElseIf $i_number_of_records > 0 Then
                    If MsgBox(BitOR(4, 32, 262144), "", "*SomeQuestion*") = 6 Then
                        Local $s_SQL_query = "SELECT * FROM *tableName* WHERE " & '*colName*"=' & "'" & $s_mobile_number & "';"
                        ConsoleWrite($s_SQL_query & @CRLF)
                        Local $arr_earlier_errands_2 = _SQLGetArray($obj_SQL_conn, $s_SQL_query)
                        If @error Then MsgBox(0, "", "Funktion: _SQLGetArray" & @CRLF & @error & @CRLF & @extended)
                        _SQLDisconnect($obj_SQL_conn)
                        _ArrayDisplay($arr_earlier_errands_2)
                        _showMyErrandsGUI($arr_earlier_errands)
                        Return 1
;~                      
                    Else
                        Return 1
                    EndIf ; <== If MsgBox(BitOR(4, 32, 262144), "", "*someQuestion*") = 6 Then
                EndIf
            EndIf ; <== If StringRegExp($s_mobile_number, "\A(07[0-9]{8})") Then

        EndIf ; <== If $hwnd_GUICtrl = GUICtrlGetHandle($input_mobilenumber) Then
    EndIf ; <== If $nNotifyCode = $EN_CHANGE Then
EndFunc  ;==>My_WM_COMMAND
Edited by MaxEdman
Link to comment
Share on other sites

When you are inside the function, the message pump is locked and subsequent messages are queued. You must return as quickly as possible so that normal Windows processing can continue. There is a warning in GUIRegisterMsg about this. It certainly isn't the place to connect to a remote SQL engine and query it!

Also the lockup occurs when you try to affect the GUI: the message pump is waiting for your function to return (quickly) but instead you instruct it to perform actions (_ArrayDisplay, MsgBox and such) that queue in the locked message pump. You have created a deadlock condition.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
Share on other sites

When you are inside the function, the message pump is locked and subsequent messages are queued. You must return as quickly as possible so that normal Windows processing can continue. There is a warning in GUIRegisterMsg about this. It certainly isn't the place to connect to a remote SQL engine and query it!

Also the lockup occurs when you try to affect the GUI: the message pump is waiting for your function to return (quickly) but instead you instruct it to perform actions (_ArrayDisplay, MsgBox and such) that queue in the locked message pump. You have created a deadlock condition.

 

Ok! Thanks.

What is the smartest way of get the Returnmessage from this function? So that I can continue my coding when the above is correct?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...