Laufwerksabfrage: Array löschen

  • Das Problem an sich ist, dass die Labels mit einem Array erstellt werden.
    Wird die Funktion erneut ausgeführt, werden diese zwar gelöscht, aber das Array hat mehr Plätze, womit es auf Dauer zum Speicherfresser wird, ich finde leider den Fehler nicht. ?(

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include "GUICtrlOnHover.au3"
    #include <ButtonConstants.au3>
    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hGui = GUICreate("Test", 754, 420, 173, 131)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    [/autoit] [autoit][/autoit] [autoit]

    $cmd_ok = GUICtrlCreateButton("&Ok",299, 368, 75, 25, $BS_NOTIFY)
    GUICtrlSetOnEvent(-1, "_drives")

    [/autoit] [autoit][/autoit] [autoit]

    Global $c
    Global $aLabels[1] = [$c]
    Global $bDelete

    [/autoit] [autoit][/autoit] [autoit]

    Func _drives ()
    If $bDelete = True Then
    For $i = 0 To UBound($aLabels) -1
    GuiCtrlDelete($aLabels[$i])
    MsgBox(0,"",$aLabels[$i])
    Next
    EndIf
    Global $aDrives = DriveGetDrive("all")
    $c = $aDrives[0]
    MsgBox(0,"",$c)
    Global $iX
    Global $drfree
    $iX = 17
    Local $i , $sDriveState, $sTmp ,$upper ,$round

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $c
    $sDriveState = DriveStatus($aDrives[$i])
    $drfree = DriveSpaceFree ($aDrives[$i])
    $roundfree = Round(($drfree/1024),2)
    $drtotal = DriveSpaceTotal ($aDrives[$i])
    $roundtotal = Round(($drtotal/1024),2)
    $drsystem = DriveGetFileSystem($aDrives[$i])
    If $drtotal <> 0 Then
    If $sDriveState <> "UNKNOWN" And $sDriveState <> "INVALID" Then
    $sTmp = DriveGetLabel($aDrives[$i])
    EndIf
    If $sTmp = '' Then
    _CreateLabel(StringUpper($aDrives[$i]) & @CRLF, $iX, 40, 51, 35, 0x01)
    Else
    _CreateLabel(StringUpper($aDrives[$i]) & @CRLF & '(' & $sTmp & ')', $iX, 40, 51, 35, 0x01)
    EndIf
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    _CreateLabel("Gesamt: ", $iX+8, 84, 49, 17, 0)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    _CreateLabel($roundtotal & " GB", $iX+8, 112, -1, -1, 0)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    _CreateLabel("Frei: ", $iX+8, 139, 30, 17, 0)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    _CreateLabel($roundfree & " GB", $iX+8, 166, -1, -1, 0)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    _CreateLabel("Dateisystem: ", $iX+8, 197, -1, -1, 0)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    _CreateLabel($drsystem, $iX+8, 224, -1, -1, 0)
    $iX = $iX +91
    EndIf
    Next
    $bDelete = True
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _CreateLabel($sText, $iX, $iY, $iW, $iH, $iSt)
    Local $iIndex = $aLabels[0] + 1
    ReDim $aLabels[$iIndex + 1]
    $aLabels[0] = $iIndex
    $aLabels[$iIndex] = GUICtrlCreateLabel($sText, $iX , $iY, $iW, $iH, $iSt)
    GUICtrlSetOnEvent($aLabels[$iIndex], "_drives")
    EndFunc ;==>_CreateLabel

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc ;==>_Exit

    [/autoit]

    Zur Info:
    Die erste MsgBox zeigt die Anzahl der erkannten Laufwerke. Alle Laufwerke mit der Gesamtgröße von 0 werden übersprungen.
    Sobald die Funktion mittels des Buttons erneut ausgeführt wird, zeigt die zweite MsgBox die Gesamtzahl des Arrays angezeigt und dann alle nach einander gelöscht. Jedoch wird am eine eine höhere Zahl gezeigt.

    Chuck

    Einmal editiert, zuletzt von ChuckSOG (15. Oktober 2011 um 20:32)

  • An ListView hab ich auch schon gedacht, aber letztendlich soll es alles auf einer Seite zusammengefasst werden (ist nur ein Teil des Programmes)

    Wenn ich es jetzt in die GuiCtrlDelete Schleife einfüge, löscht er scheinbar beliebig die Labels.

    Was mach ich falsch? :S

    [autoit]

    Func _drives ()
    If $bDelete = True Then
    For $i = 0 To UBound($aLabels) -1
    GuiCtrlDelete($aLabels[$i])
    _ArrayDelete($aLabels,$i)
    MsgBox(0,"",$aLabels[$i])
    Next
    EndIf

    [/autoit]
  • Hi,


    Setzt am ende der Löschschleife das Arrayindex Null auf Null ;)

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    ;#include "GUICtrlOnHover.au3"
    #include <ButtonConstants.au3>
    #include <Array.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Opt("GUIOnEventMode", 1)

    [/autoit] [autoit][/autoit] [autoit]

    $hGui = GUICreate("Test", 754, 420, 173, 131)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    [/autoit] [autoit][/autoit] [autoit]

    $cmd_ok = GUICtrlCreateButton("&Ok", 299, 368, 75, 25, $BS_NOTIFY)
    GUICtrlSetOnEvent(-1, "_drives")

    [/autoit] [autoit][/autoit] [autoit]

    Global $c
    Global $aLabels[1]
    Global $bDelete

    [/autoit] [autoit][/autoit] [autoit]

    Func _drives()
    If $bDelete = True Then
    For $i = 0 To UBound($aLabels) - 1
    GUICtrlDelete($aLabels[$i])
    ConsoleWrite('-Löschen:' & @TAB & $aLabels[$i] & @TAB &UBound($aLabels)&@CRLF)
    Next
    $aLabels[0] = 0
    EndIf
    Global $aDrives = DriveGetDrive("all")
    $c = $aDrives[0]
    MsgBox(0, "", $c)
    Global $iX
    Global $drfree
    $iX = 17
    Local $i, $sDriveState, $sTmp, $upper, $round

    [/autoit] [autoit][/autoit] [autoit]

    For $i = 1 To $c
    $sDriveState = DriveStatus($aDrives[$i])
    $drfree = DriveSpaceFree($aDrives[$i])
    $roundfree = Round(($drfree / 1024), 2)
    $drtotal = DriveSpaceTotal($aDrives[$i])
    $roundtotal = Round(($drtotal / 1024), 2)
    $drsystem = DriveGetFileSystem($aDrives[$i])
    If $drtotal <> 0 Then
    If $sDriveState <> "UNKNOWN" And $sDriveState <> "INVALID" Then
    $sTmp = DriveGetLabel($aDrives[$i])
    EndIf
    If $sTmp = '' Then
    _CreateLabel(StringUpper($aDrives[$i]) & @CRLF, $iX, 40, 51, 35, 0x01)
    Else
    _CreateLabel(StringUpper($aDrives[$i]) & @CRLF & '(' & $sTmp & ')', $iX, 40, 51, 35, 0x01)
    EndIf
    GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    _CreateLabel("Gesamt: ", $iX + 8, 84, 49, 17, 0)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    _CreateLabel($roundtotal & " GB", $iX + 8, 112, -1, -1, 0)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    _CreateLabel("Frei: ", $iX + 8, 139, 30, 17, 0)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    _CreateLabel($roundfree & " GB", $iX + 8, 166, -1, -1, 0)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    _CreateLabel("Dateisystem: ", $iX + 8, 197, -1, -1, 0)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    _CreateLabel($drsystem, $iX + 8, 224, -1, -1, 0)
    $iX = $iX + 91
    EndIf
    Next
    $bDelete = True
    EndFunc ;==>_drives

    [/autoit] [autoit][/autoit] [autoit]

    GUISetState()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While Sleep(100)
    WEnd

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _CreateLabel($sText, $iX, $iY, $iW, $iH, $iSt)
    Local $iIndex = $aLabels[0] + 1
    ConsoleWrite('+ReDim:' & @TAB & $aLabels[0] & @CRLF)
    ReDim $aLabels[$iIndex + 1]
    $aLabels[0] = $iIndex
    $aLabels[$iIndex] = GUICtrlCreateLabel($sText, $iX, $iY, $iW, $iH, $iSt)
    GUICtrlSetOnEvent($aLabels[$iIndex], "_drives")
    EndFunc ;==>_CreateLabel

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _Exit()
    Exit
    EndFunc ;==>_Exit

    [/autoit]


    Lg kleiner