|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Rawing Cheater Reputation: 0
Joined: 01 May 2010 Posts: 42 Location: Austria
|
Posted: Tue May 12, 2015 10:41 am Post subject: Remove Controls from Form |
|
|
I'm trying to remove Controls (buttons, labels, etc...) from a Form. I wrote the following code:
Code: | function wipe_window()
--for _, control in pairs(win.Control) do --the Control array is always empty, unexpectedly
-- control:destroy()
--end
while win.ControlCount > 0 do
local control= win:getControl(0)
control:destroy()
end
end
win= createForm()
control_setSize(win, 200, 200)
w= createButton(win)
control_setCaption(w, "wipe")
control_setPosition(w, 5, 5)
w.onClick= wipe_window |
It does remove all Controls, but it also produces an "access violation" error or causes Cheat Engine to hang. What am I doing wrong?
_________________
Game over! Die again! |
|
Back to top |
|
|
panraven Grandmaster Cheater Reputation: 55
Joined: 01 Oct 2008 Posts: 942
|
Posted: Tue May 12, 2015 11:48 am Post subject: |
|
|
It seems this work by using a callLater function:
Code: |
local function callLater(d,f,...)
local t,a,n = createTimer(),{...},select('#',...)
t.Interval = d
t.OnTimer = function(sender) sender.Destroy() f(unpack(a,1,n)) end
t.Enabled = true
return t
end
function wipe_window()
for i=0,win.ControlCount-1 do -- can't use WHILE as controlCount is not updated
local control= win:getControl(i)
callLater(1,control.destroy)
end
end
win= createForm()
control_setSize(win, 200, 200)
for i=1,5 do
local w= createButton(win)
control_setCaption(w, "wipe "..i)
control_setPosition(w, 5, 5+i*25)
w.onClick= wipe_window
end
|
Also this work without using callLater:
Code: | function wipe_window(sender) -- added the sender/owner parameter
local next = 0
while win.ControlCount > 1 do -- one button should left which is the one being clicked,ie. sender
local control= win:getControl(next)
if control ~= sender then control.destroy() else next = 1 end
end
end
win= createForm()
control_setSize(win, 200, 200)
for i=1,5 do
local w= createButton(win)
control_setCaption(w, "wipe "..i)
control_setPosition(w, 5, 5+i*25)
w.onClick= wipe_window
end |
... but this might not what you intended, as one child control is left.
This only to show that, if control.Destroy is calling from OnClick function of the exact control of owner/sender, it may be the cause of access violation.
Finally, still using callLater, but least modifying your code,
Code: | function wipe_window2()
while win.ControlCount > 0 do
local control= win:getControl(0)
control.destroy()
end
end
function wipe_window() callLater(1,wipe_window2) end
|
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25288 Location: The netherlands
|
Posted: Tue May 12, 2015 2:16 pm Post subject: |
|
|
don't destroy the caller
also, instead of destroy, set visible to false
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Rawing Cheater Reputation: 0
Joined: 01 May 2010 Posts: 42 Location: Austria
|
Posted: Tue May 12, 2015 4:59 pm Post subject: |
|
|
Thanks for the help guys. I'll have to rewrite some parts of my code.
_________________
Game over! Die again! |
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Tue May 12, 2015 7:36 pm Post subject: |
|
|
Code: | function wipe_window()
--for _, control in pairs(win.Control) do --the Control array is always empty, unexpectedly
-- control:destroy()
--end
while win.ControlCount > 0 do
local control= win:getControl(0)
control:destroy()
end
end
win= createForm()
control_setSize(win, 200, 200)
w= createButton(win)
control_setCaption(w, "wipe")
control_setPosition(w, 5, 5)
w.onMouseUp= wipe_window -- this.. |
_________________
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|