Jump to content

Recommended Posts

Posted (edited)

Hello everybody :)

What is the correct way to remove all keys at once in a Map declared as Local Static ?

Because cycling through all the keys to remove them one by one isn't user friendly and not a good solution in case of a big Map.
I found a way to do it, but maybe you know if there is a native instruction that does it better ?

Please have a look at the following canvas, where a user drags one of the Tab controls inside the GUI to move it at a different place (they may be several Tab controls in the GUI as stated in the help file, function GUICtrlCreateTab) :

A GUI can only hold a single tab control, but it is possible to create child GUIs each holding a tab control.

 

Func WM_ENTERSIZEMOVE($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $g_hGUIMask
            If $g_sClassName = "SysTabControl32" Then
                _TabIsMoving($g_idControl, $WM_ENTERSIZEMOVE)
            EndIf
        Case ...
            ...
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_ENTERSIZEMOVE

Func WM_MOVE($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $g_hGUIMask
            ... ; any control of the GUI just moved here (Tab control or other control), then :
            If $g_sClassName = "SysTabControl32" Then
                _TabIsMoving($g_idControl, $WM_MOVE)
            EndIf
        Case ...
            ...
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_MOVE

Func WM_EXITSIZEMOVE($hWnd, $iMsg, $wParam, $lParam)
    Switch $hWnd
        Case $g_hGUIMask
            If $g_sClassName = "SysTabControl32" Then
                _TabIsMoving($g_idControl, $WM_EXITSIZEMOVE)
            EndIf
        Case ...
            ...
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_EXITSIZEMOVE

Func _TabIsMoving($idTab, $iStage)
    ; called by WM_ENTERSIZEMOVE / WM_MOVE / WM_EXITSIZEMOVE
    ; NO MsgBox, _ArrayDisplay or any blocking function here !

    Local Static $mCtrl[]

    Switch $iStage
        Case $WM_ENTERSIZEMOVE
            ; populate $mCtrl[] just before a Tab control enters the moving/sizing modal loop.
            ...

        Case $WM_MOVE
            ; use $mCtrl[] keys & values while the user drags a Tab control
            ...

        Case $WM_EXITSIZEMOVE
            ; empty $mCtrl[] just after a Tab control has exited the moving/sizing modal loop.
            Local $mAlwaysEmpty[] ; no need to make this one Static too
            $mCtrl = $mAlwaysEmpty
    EndSwitch
EndFunc   ;==>_TabIsMoving

As you notice, a 2nd map ($mAlwaysEmpty) has been used to quickly clear all keys in $mCtrl, is it the correct way ?

For the record, if a Local Static Array (or Scripting.Dictionary) was used instead of the Local Static Map, then native functions already exist to quickly clear the Array or Dictionary Object (while keeping it Static) i.e.
* For an array : ReDim $aCtrl[0][...]
* For a dictionary object : $oCtrl.RemoveAll()

Thanks for reading and have a great day :bye:

Edited by pixelsearch
typo

"I think you are searching a bug where there is no bug... don't listen to bad advice."

  • pixelsearch changed the title to How to remove all keys at once in a Static Map ?
Posted
3 hours ago, pixelsearch said:

is it the correct way ?

Seems pretty good. Also you can make the empty map static too, no need to reallocate it multiple times.

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)

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
×
×
  • Create New...