Modify ↓
Opened 4 years ago
#3767 new Feature Request
Defer keyword
Reported by: | matwachich@… | Owned by: | |
---|---|---|---|
Milestone: | Component: | AutoIt | |
Version: | Severity: | None | |
Keywords: | defer keyword | Cc: |
Description
Why not a Defer keyword for the AutoIt language?
Just like https://golangbot.com/defer/
Code is much more clear and clean when Close/Terminate/Deinit/Destroy is just below the corresponding Open/Startup/Init/Create.
And lesser memory leaks (handle not closed...).
Func readFile($sFile) Local $hF = FileOpen($sFile) Defer FileClose($hF) Return FileRead($sFile) EndFunc Func doStuff() Local $hDC = _WinAPI_GetDC() Local $hFont = _WinAPI_CreateFont() Local $hOld = _WinAPI_SelectObject($hDC, $hFont) Defer _WinAPI_SelectObject($hDC, $hOld) _WinAPI_DestroyObject($hFont) _WinAPI_ReleaseDC($hDC) EndDefer ... do stuff, and don't care about ressources freeing ... EndFunc ; OR Func doStuff() Local $hDC = _WinAPI_GetDC() Defer _WinAPI_ReleaseDC($hDC) Local $hFont = _WinAPI_CreateFont() Defer _WinAPI_DestroyObject($hFont) Local $hOld = _WinAPI_SelectObject($hDC, $hFont) Defer _WinAPI_SelectObject($hDC, $hOld) ... do stuff, and don't care about ressources freeing ... EndFunc
Attachments (0)
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.
Note: See
TracTickets for help on using
tickets.