Attaching string as GadgetData
Attaching string as GadgetData
Do I have to attach a string pointer to Gadgets seeing that the Get/SetGadgetData value parameter only accepts integers or is there a simpler way I am missing?
PB 5.73 on Windows 10 & OS X High Sierra
- Fangbeast
- PureBasic Protozoa
- Posts: 4749
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Attaching string as GadgetData
G'day, I asked about this ages ago and the answer was yes. By using pointers, you can even attach entire structures to gadgets that way.
Mind you, I still don't quite know how to use this.
Mind you, I still don't quite know how to use this.
Amateur Radio, D-STAR/VK3HAF
Re: Attaching string as GadgetData
Yep. The help file gives you one approach using arrays. But you probably prefer the following;
Code: Select all
If OpenWindow(0, 0, 0, 190, 100, "SetGadgetData", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 80, 20, "Button"): SetGadgetData(0, @"Good morning")
ButtonGadget(1, 10, 40, 80, 20, "Button"): SetGadgetData(1, @"Hello World")
ButtonGadget(2, 10, 70, 80, 20, "Button"): SetGadgetData(2, @"Nothing to say")
ButtonGadget(3, 100, 10, 80, 20, "Button"): SetGadgetData(3, @"Nothing to say")
ButtonGadget(4, 100, 40, 80, 20, "Button")
ButtonGadget(5, 100, 70, 80, 20, "Button")
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Value = GetGadgetData(EventGadget())
If Value
Debug PeekS(Value)
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
ʽʽSuccess is almost totally dependent upon drive and persistence. The extra energy required to make another effort or try another approach is the secret of winning.ʾʾ --Dennis Waitley
- Fangbeast
- PureBasic Protozoa
- Posts: 4749
- Joined: Fri Apr 25, 2003 3:08 pm
- Location: Not Sydney!!! (Bad water, no goats)
Re: Attaching string as GadgetData
Code: Select all
simply this (only demonstration)
I went searching anf found a good example from Bisonte (to me) about simple use of structure if you needed more than a string pointer.
[code]
Structure struct
Text.s
Integer.i
EndStructure
*Pointer.struct = AllocateMemory(SizeOf(struct))
If *Pointer
*Pointer\Text = "Hello"
SetGadgetData(#Gadget, *Pointer) ; Or SetGadgetItemData(#Gadget, Item, *Pointer)
[...]
*MyPointer.struct = GetGadgetData(#Gadget) ; or GetGadgetItem(#Gadget, Item)
Debug *MyPointer\Text
EndIf
Amateur Radio, D-STAR/VK3HAF
Re: Attaching string as GadgetData
Or without something of "pointermagic"
Code: Select all
Global NewMap mGadgetText.s()
Procedure.i SetGadgetDataText(Gadget, Text.s)
Protected Result = #False, Key.s = Hex(Gadget)
If IsGadget(Gadget)
mGadgetText(Key) = Text
Result = #True
EndIf
ProcedureReturn Result
EndProcedure
Procedure.s GetGadgetDataText(Gadget)
Protected Key.s = Hex(Gadget)
Protected Result.s = ""
If FindMapElement(mGadgetText(), Key)
Result = mGadgetText(Key)
EndIf
ProcedureReturn Result
EndProcedure
Procedure.i RemoveGadgetDataText(Gadget)
Protected Key.s = Hex(Gadget)
Protected Result = #False
If FindMapElement(mGadgetText(), Key)
DeleteMapElement(mGadgetText(), Key)
Result = #True
EndIf
ProcedureReturn Result
EndProcedure
Re: Attaching string as GadgetData
@Bisonte
very nice
I have this Modul. Named GadgetData http://www.purebasic.fr/english/viewtop ... 12&t=63937
very nice
I have this Modul. Named GadgetData http://www.purebasic.fr/english/viewtop ... 12&t=63937
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive