SetGadgetData()

Syntax

SetGadgetData(#Gadget, Value)
Description
Stores the given value with the specified gadget. This value can later be read with the GetGadgetData() function. This allows to associate a custom value with any gadget.

Parameters

#Gadget The gadget to use.
Value The value to set.

Return value

None.

Example

  ; This code uses SetGadgetData to associate an index for the Messages()
  ; array with each button. This makes the event loop simpler as not every
  ; gadget needs to he handled separately.
  ;
  Dim Messages.s(2)
  Messages(0) = "Good morning"
  Messages(1) = "Hello World"
  Messages(2) = "Nothing to say"
  If OpenWindow(0, 0, 0, 190, 100, "SetGadgetData", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
    ButtonGadget(0,  10, 10, 80, 20, "Button"): SetGadgetData(0, 1)
    ButtonGadget(1,  10, 40, 80, 20, "Button"): SetGadgetData(1, 2)
    ButtonGadget(2,  10, 70, 80, 20, "Button"): SetGadgetData(2, 1)
    ButtonGadget(3, 100, 10, 80, 20, "Button"): SetGadgetData(3, 2)
    ButtonGadget(4, 100, 40, 80, 20, "Button") ; will have the value 0 because nothing was set yet
    ButtonGadget(5, 100, 70, 80, 20, "Button")
    Repeat
      Event = WaitWindowEvent()
      If Event = #PB_Event_Gadget
        Value = GetGadgetData(EventGadget())
        MessageRequester("Message", Messages(Value))
      EndIf
    Until Event = #PB_Event_CloseWindow
  EndIf

See Also

GetGadgetData(), GetGadgetItemData(), SetGadgetItemData()

Supported OS

All

<- SetGadgetColor() - Gadget Index - SetGadgetFont() ->