Jump to content
Sign in to follow this  
CrewXp

Best Way to Delete Objects created and put in a stack?

Recommended Posts

CrewXp

Hey, I'm creating GUI items, and after they're created, it puts them on a stack (i think its right...)

But I want to call a function that deletes all of the ones on a stack when I'm done. What's the best way to do this?

;Test
#include <Array.au3>
Dim $cleanupstack
$file = GUICtrlCreateInput ( "Password :: ", 10,  100, 220, 20)
$btn = GUICtrlCreateButton ("Ok", 10,  150, 60, 20)
_ArrayAdd( $cleanupStack,$file)
_ArrayAdd( $cleanupStack,$btn)

Func CleanUp()
For $i=0 To _ArrayMaxIndex( $avArray, 1, 1)
                GUICtrlDelete(_ArrayPop($avArray))
Next
EndFunc

I'm not even sure if this works, as I'm not sure how to properly test it in my long code. Could someone help me out with this? Thanks.

Share this post


Link to post
Share on other sites
Sunaj

Your code should work fine but I would use:

For $i=1 To Ubound($avArray) -1
    GUICtrlDelete($avArray[$i])
Next

It is faster and no includes are needed that way :)

Hey, I'm creating GUI items, and after they're created, it puts them on a stack (i think its right...)

But I want to call a function that deletes all of the ones on a stack when I'm done. What's the best way to do this?

;Test
#include <Array.au3>
Dim $cleanupstack
$file = GUICtrlCreateInput ( "Password :: ", 10,  100, 220, 20)
$btn = GUICtrlCreateButton ("Ok", 10,  150, 60, 20)
_ArrayAdd( $cleanupStack,$file)
_ArrayAdd( $cleanupStack,$btn)

Func CleanUp()
For $i=0 To _ArrayMaxIndex( $avArray, 1, 1)
                GUICtrlDelete(_ArrayPop($avArray))
Next
EndFunc

I'm not even sure if this works, as I'm not sure how to properly test it in my long code. Could someone help me out with this? Thanks.

Share this post


Link to post
Share on other sites
CrewXp

doesn't work... :)

I didn't think something that I wrote on the fly would actually work...

any suggestions?

#include <Array.au3>
Dim $cleanupstack

HotKeySet("{F6}","test")
HotKeySet("{F7}","test2")
Func test()
$file = GUICtrlCreateInput ( "Password :: ", 10,  100, 220, 20)
$btn = GUICtrlCreateButton ("Ok", 10,  150, 60, 20)
_ArrayAdd( $cleanupstack,$file)
_ArrayAdd( $cleanupstack,$btn)
EndFunc

Func test2()
;Msgbox(0,"",Ubound($cleanupstack))
For $i=0 To _ArrayMaxIndex( $cleanupstack, 1, 1)
                GUICtrlDelete(_ArrayPop($cleanupstack))
Next
EndFunc

Share this post


Link to post
Share on other sites
CrewXp

*bump*

I'm stuck on this little problem for now, as it's holding my entire code back. So help is GREATLY appreciated!! Thanks :)

Edit: Still trying. No luck.

Share this post


Link to post
Share on other sites
CrewXp

I'm dumb... got it figured out.

Share this post


Link to post
Share on other sites
rover

if you manually create array and items and don't use element zero for number of elements in array then you can use

a For $element In $Array loop

Local $avArray[2]

HotKeySet("{F6}","test")
HotKeySet("{F7}","test2")

$gui = GUICreate("",240,200)
GUISetState()

While 1
    Sleep(20)
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit ; -3 is GUI constant $GUI_EVENT_CLOSE from #include <GUIConstants.au3>
Wend

Func test()
    $avArray[0] = GUICtrlCreateInput ( "Password :: ", 10,  100, 220, 20)
    $avArray[1] = GUICtrlCreateButton ("Ok", 10,  150, 60, 20)
EndFunc

Func test2()
    For $element In $avArray
        GUICtrlDelete($element)
    Next
EndFunc

I see fascists...

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  

×