Hallo zusammen =)
Da ich sehr oft Consolewrite benutze um Inhalte von Variablen auf ihre Richtigkeit zu prüfen habe ich mir eine UDF geschrieben, die alle Variablen im aktuellen Script inkl. des Variablentyps und Wert in einer Listview zusammen stellt. Es werden aber nur die Variablen die in dem Script selber deklariert werden bzw. benutzt werden angezeigt. Zusätzlich kann man die Werte der Variablen noch manipulieren, dies funktioniert aber noch nicht mit Arrays. Zusätzlich kann man das Script auch noch anhalten, damit man sich in Ruhe die Werte der Variablen anschauen kann und sie sich nicht verändern.
Das Script funktioniert erstmal nur ausschließlich im nicht kompilierten Zustand, hab da ne idee wie es gehen könnte wenn das Script kompiliert wurde, aber das halte ich für schwachsinnig, den Debugger zu nuzten wenn das Script kompiliert wurde, da man eh nix mehr ändern kann.
So sieht das ganze aus:
Spoiler anzeigen
[Blockierte Grafik: http://djbaselord.kilu.de/autoit/debugger.png]
Hier der Code:
Spoiler anzeigen
#include <array.au3>
#include <GUIListView.au3>
#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
Global $bDebugMode = 0; 0 = silence, 1 = show bugs
Dim $asVars[1]
Dim $hListview, $hGUI_Debugger, $iTime, $iCurrentSelect, $iOldSelect , $hLabelVarName, $hInputVarWert
Dim $hButtonAssign,$hButtonPause, $bShutDown = 0
;=============================================== _DebuggerInit =============================================
;
; Author: DJ Baselord
;
; Version: 1.0
;
; Function: Needed to initialize the debugger window
;
; Parameters: $iX: x coordinate which to create the window to
; $IY: y coordinate which to create the window to
; $bTopMost: Set it to 1 if you want to create debug window on topmost level, otherwise to 0
;
; Returnvalue: Nothing
;
;===========================================================================================================
Func _DebuggerInit($iX=-1,$iY=-1,$bTopMost=1)
Local $iSTYLE = -1
If Not @Compiled Then
If $bTopMost Then $iSTYLE = $WS_EX_TOPMOST
$hFileOpen = FileOpen(@ScriptFullPath,0)
$sFileRead1 = FileRead($hFileOpen)
FileClose($hFileOpen)
$asVars = StringRegExp( $sFileRead1 ,"([$][\w]+)",3)
$hGUI_Debugger = GUICreate("_AutoitDebugger",500,250,$iX,$iY,-1,$iSTYLE)
GUISetState()
$hListview = _GUICtrlListView_Create($hGUI_Debugger,"Variable|Typ|Wert",10,10,480,200)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
$hButtonAssign = GUICtrlCreateButton("Wert Ändern",280,220,100,20)
GUICtrlSetState(-1,$GUI_DISABLE)
$hButtonPause = GUICtrlCreateButton("Script Anhalten",390,220,100,20)
$hLabelVarName = GUICtrlCreateLabel("",10,220,150,20,$SS_CENTERIMAGE)
$hInputVarWert = GUICtrlCreateInput("",170,220,100,20,$ES_AUTOHSCROLL)
GUICtrlSetState(-1,$GUI_DISABLE)
_GUICtrlListView_SetColumnWidth($hListview,0,150)
_GUICtrlListView_SetColumnWidth($hListview,1,100)
_GUICtrlListView_SetColumnWidth($hListview,2,210)
_Array2DDblDel($asVars)
$i = 0
For $sVarName In $asVars
$sWert = Eval(StringTrimLeft($sVarName,1))
If IsArray($sWert) Then
$e = 0
For $asWert In $sWert
$sType = VarGetType($asWert)
_GUICtrlListView_AddItem($hListview,$sVarName&"["&$e&"]")
_GUICtrlListView_AddSubItem($hListview,$i,$sType,1)
_GUICtrlListView_AddSubItem($hListview,$i,$asWert,2)
$e += 1
$i += 1
Next
Else
$sType = VarGetType($sWert)
_GUICtrlListView_AddItem($hListview,$sVarName)
_GUICtrlListView_AddSubItem($hListview,$i,$sType,1)
_GUICtrlListView_AddSubItem($hListview,$i,$sWert,2)
$i+=1
EndIf
Next
Return 1
Else
If $bDebugMode Then MsgBox(64,"_AutoitDebugger","This program is only able to run in uncompiled scripts.")
Return SetError(1,0,0)
EndIf
EndFunc
;=============================================== _DebuggerUpdate ===========================================
;
; Author: DJ Baselord
;
; Version: 1.0
;
; Function: This function will automatically date up the debugger window
;
; Parameters: $iTime: leave it up to 0 and the update window will be updated 1 time
; set $iTime > 0 will force to autoupdate the debuggerwindow every x ms
; set $iTime to -1 and the autoupdate wont be called anylonger
;
; Returnvalue: Nothing
;
;===========================================================================================================
Func _DebuggerUpdate($iTime = "")
If $iTime And IsNumber($iTime) Then Return AdlibEnable("_DebuggerUpdate",$iTime)
If IsNumber($iTime) And $iTime = -1 Then Return AdlibDisable()
$i = 0
For $sVarName In $asVars
$sWert = Eval(StringTrimLeft($sVarName,1))
If IsArray($sWert) Then
$e = 0
For $asWert In $sWert
$sType = VarGetType($asWert)
If Not (_GUICtrlListView_GetItemText($hListview,$i,1) = $sType) Then _GUICtrlListView_SetItemText($hListview,$i,$sType,1)
If Not (_GUICtrlListView_GetItemText($hListview,$i,2) = $asWert) Then _GUICtrlListView_SetItemText($hListview,$i,$asWert,2)
$e += 1
$i += 1
Next
Else
$sType = VarGetType($sWert)
If Not (_GUICtrlListView_GetItemText($hListview,$i,1) = $sType) Then _GUICtrlListView_SetItemText($hListview,$i,$sType,1)
If Not (_GUICtrlListView_GetItemText($hListview,$i,2) = $sWert) Then _GUICtrlListView_SetItemText($hListview,$i,$sWert,2)
$i+=1
EndIf
Next
$iCurrentSelect = _GUICtrlListView_GetSelectedIndices($hListView)
If Not ($iCurrentSelect = $iOldSelect) Then
$sVarName = _GUICtrlListView_GetItemText($hListView,$iCurrentSelect,0)
GUICtrlSetData($hLabelVarName,$sVarName)
GUICtrlSetData($hInputVarWert,_GUICtrlListView_GetItemText($hListView,$iCurrentSelect,2))
If StringRegExp($sVarName,"([\[][\d]+[\]])",0) Then
GUICtrlSetState($hInputVarWert,$GUI_DISABLE)
GUICtrlSetState($hButtonAssign,$GUI_DISABLE)
Else
GUICtrlSetState($hInputVarWert,$GUI_ENABLE)
GUICtrlSetState($hButtonAssign,$GUI_ENABLE)
EndIf
EndIf
If Not $iCurrentSelect Then
GUICtrlSetState($hInputVarWert,$GUI_DISABLE)
GUICtrlSetState($hButtonAssign,$GUI_DISABLE)
EndIf
$iOldSelect = $iCurrentSelect
Return 1
EndFunc
;=============================================== _DebuggerSendMsg ==========================================
;
; Author: DJ Baselord
;
; Version: 1.0
;
; Function: This function is needed to handle messages receipt on the debugger window
;
; Parameters: msg - value returned by GUIGetMsg()
;
; Returnvalue: Nothing
;
;===========================================================================================================
Func _DebuggerSendMsg($Msg)
Switch $Msg
Case $hButtonAssign
Assign(StringTrimLeft(GUICtrlRead($hLabelVarName),1),GUICtrlRead($hInputVarWert),4)
Case $hButtonPause
GUICtrlSetData($hButtonPause,"Script fortführen")
While 1
If $bShutDown Then ExitLoop
Switch GUIGetMsg()
Case $hButtonAssign
Assign(StringTrimLeft(GUICtrlRead($hLabelVarName),1),GUICtrlRead($hInputVarWert),4)
Case $hButtonPause
ExitLoop
EndSwitch
WEnd
GUICtrlSetData($hButtonPause,"Script anhalten")
EndSwitch
EndFunc
;=============================================== _DebuggerShutdown =========================================
;
; Author: DJ Baselord
;
; Version: 1.0
;
; Function: This function shuts the debugger down and also fores the autoupadte to end
;
; Parameters: msg - value returned by GUIGetMsg()
;
; Returnvalue: Nothing
;
;===========================================================================================================
Func _DebuggerShutdown()
GUIDelete($hGUI_Debugger)
_DebuggerUpdate(-1)
EndFunc
#Region internal stuff, thx to Bugfix for his great function =)
;----------------------------------------------------------------------------------------------------------------------
; Function _Array2DDblDel(ByRef $ARRAY [, $CASESENS=0])
;
; Description - From an 1D/2D Array will delete double entries (2D -> combination by '[n][0]' to '[n][x]').
; - Autodetection 1D/2D Array
; - By using string, you can choose case sensitivity.
;
; Parameter $ARRAY: Array to sort
; optional $CASESENS: Case sensitivity off[0] or on[1] (default 0)
;
; Return Succes ByRef Array without doubles
; Count of doubles
; Failure 0 and set @error = 1; no array
;
; Author BugFix ([email='bugfix@autoit.de'][/email])
;----------------------------------------------------------------------------------------------------------------------
Func _Array2DDblDel(ByRef $ARRAY, $CASESENS=0)
Local $iDIM, $arTmp[1] = [''], $dbl = 0, $count = 0
If ( Not IsArray($ARRAY) ) Then
SetError(1)
Return 0
EndIf
$Ubound2nd = UBound($ARRAY,2)
If @error = 2 Then
For $i = 0 To UBound($ARRAY)-1
$dbl = 0
For $k = 0 To UBound($arTmp)-1
Switch $CASESENS
Case 0
If $arTmp[$k] = $ARRAY[$i] Then
$dbl = 1
$count += 1
EndIf
Case 1
If $arTmp[$k] == $ARRAY[$i] Then
$dbl = 1
$count += 1
EndIf
EndSwitch
Next
If $dbl = 0 Then
If $arTmp[0] = "" Then
$arTmp[0] = $ARRAY[$i]
Else
ReDim $arTmp[UBound($arTmp)+1]
$arTmp[UBound($arTmp)-1] = $ARRAY[$i]
EndIf
Else
$dbl = 0
EndIf
Next
Else
ReDim $arTmp[1][$Ubound2nd]
$arTmp[0][0] = ''
$x = 0
For $i = 0 To UBound($ARRAY)-1
$dbl = 0
$val = ''
$valTmp = ''
For $l = 0 To $Ubound2nd-1
$val &= $ARRAY[$i][$l]
Next
For $k = 0 To UBound($arTmp)-1
For $l = 0 To $Ubound2nd-1
$valTmp &= $arTmp[$k][$l]
Next
Switch $CASESENS
Case 0
If $valTmp = $val Then
$dbl = 1
$count += 1
EndIf
Case 1
If $valTmp == $val Then
$dbl = 1
$count += 1
EndIf
EndSwitch
Next
If $dbl = 0 Then
If $x = 1 Then ReDim $arTmp[UBound($arTmp)+1][$Ubound2nd]
For $l = 0 To $Ubound2nd-1
If $arTmp[0][0] = '' Or $x = 0 Then
$arTmp[0][$l] = $ARRAY[0][$l]
If $l = $Ubound2nd-1 Then $x = 1
Else
$arTmp[UBound($arTmp)-1][$l] = $ARRAY[$i][$l]
$x = 2
If $l = $Ubound2nd-1 Then $x = 1
EndIf
Next
Else
$dbl = 0
EndIf
Next
EndIf
$ARRAY = $arTmp
Return $count
EndFunc ; ==>_ArrayDblDel
Hier ein Testscript:
Spoiler anzeigen
#include "debugger.au3"
Dim $iLabel = 100
GUICreate("Autoitdebugger Test",120,100)
$hLabel = GUICtrlCreateLabel($iLabel,10,10,100,20)
$hButton_Add = GUICtrlCreateButton("+100",10,30,100,20)
$hButton_Refresh = GUICtrlCreateButton("Aktuallisieren",10,60,100,20)
GUISetState()
_DebuggerInit(0,0)
_DebuggerUpdate(100)
While True
$msg = GUIGetMsg()
Switch $msg
Case $hButton_Add
$iLabel += 100
GUICtrlSetData($hLabel,$iLabel)
Case -3
_DebuggerShutdown()
Exit
Case $hButton_Refresh
GUICtrlSetData($hLabel,$iLabel)
EndSwitch
_DebuggerSendMsg($msg)
WEnd
Bin für Fragen und Anregen offen.
greetz DJ