Widget Candy. .GetHandle()

Widget Candy
Send Snippet To: Save this snippet to Code Collector Pro -- view all roger's snippets
language: Other
license: Other

Code for Snippet:

                
 
 
Each command that creates a widget returns a reference (handle) to the created widget. You can either store this handle within a variable at creation time or use the .GetHandle() command at any later time to get the handle of a certain widget.
 
The main purpose of the GetHandle() command is to eliminate the need to store any permanent references to your widgets. Remember, objects cannot be deleted from memory as long as a single reference to them exists, so it's a good programming style to NOT store any permanent references to your widgets, but to use the GetHandle() command any time you want to directly access a widget.
 
-- LOAD THE LIBRARY AND USE A GLOBAL VAR TO STORE A REFERENCE:
_G.GUI = require("widget_candy")
 
-- CREATE A BUTTON
_G.GUI.NewButton(
	{
	x     = 50,
	y     = 50,
	theme = "MyTheme",
	name  = "Button1",
	} )
 
-- GET THE HANDLE OF THIS BUTTON
local MyButton = _G.GUI.GetHandle("Button1")
MyButton:set("caption", "HELLO!")
 
-- OR IN SHORT:
_G.GUI.GetHandle("Button1"):set("caption", "HELLO!")
 
 
GetHandle (widgetName)
 
widgetName	(String) The name of a widget.
 
Returns:	(Widget Handle) A handle (reference) to the specified widget. This handle can then be used to access any widget methods or properties.
 
 
 
comments powered by Disqus

Info

Link to this snippet:


Download to Code Collector

To use the direct link to your snippet on CodeCollector.net either copy the html from the above section or drag the Download to Code Collector to where you would like to use it.

More Info:

Times Viewed: 21
Date Added: 2018-01-10 14:33:23
Last Modified: 2018-01-10 09:54:13

Web Analytics