[Solved] Set/GetGadgetData as strings

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

[Solved] Set/GetGadgetData as strings

Post by BarryG »

Can these be strings instead of numbers?

[Edit] Please ignore this request; see Little John's post below (it can already be done).
Last edited by BarryG on Tue Mar 10, 2020 4:03 am, edited 2 times in total.
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Set/GetGadgetData as strings

Post by Little John »

BarryG wrote:Can these be strings instead of numbers? If I need to store numbers with it, I can just do Str(number) and Val(number$), so it makes sense to make them strings instead for greater flexibility.
No. Now there is greater flexibility, because SetGadgetData() can be used to store a pointer to a structure, to an allocated memory area or to anything else you want.
BarryG
Addict
Addict
Posts: 3330
Joined: Thu Apr 18, 2019 8:17 am

Re: Set/GetGadgetData as strings

Post by BarryG »

Good point, Little John!
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Solved] Set/GetGadgetData as strings

Post by mk-soft »

For remember

Code: Select all

*pText.String = AllocateStructure(String)
*pText\s = "Hello World!"
Debug *pText\s
FreeStructure(*pText)
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
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5357
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: [Solved] Set/GetGadgetData as strings

Post by Kwai chang caine »

Litthe John wrote:No. Now there is greater flexibility, because SetGadgetData() can be used to store a pointer to a structure, to an allocated memory area or to anything else you want.
I don't know that, again yesterday i needed this option :oops: thanks Little John 8)
Thanks at BarryG, for lightning this subject and MkSoft for writing his example, always usefull for me for understanding a great text explanation 8)

Code: Select all

OpenWindow(0, x, y, 300, 200, "String en gadgetdata")
ButtonGadget(0, 10, 10, 30, 20, "Data")

*pText.String = AllocateStructure(String)
*pText\s = "Hello World!"
SetGadgetData(0, *pText)
*pText = 0
*pText = GetGadgetData(0)
Debug *pText\s
FreeStructure(*pText)

Repeat : WaitWindowEvent() :Until GetAsyncKeyState_(#VK_ESCAPE)
ImageThe happiness is a road...
Not a destination
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Solved] Set/GetGadgetData as strings

Post by mk-soft »

Kwai chang caine wrote:

Code: Select all

OpenWindow(0, x, y, 300, 200, "String en gadgetdata")
ButtonGadget(0, 10, 10, 30, 20, "Data")

*pText.String = AllocateStructure(String)
*pText\s = "Hello World!"
SetGadgetData(0, *pText)
*pText = 0
*pText = GetGadgetData(0)
Debug *pText\s
FreeStructure(*pText)

Repeat : WaitWindowEvent() :Until GetAsyncKeyState_(#VK_ESCAPE)
You forget remove pointer from gadget

Code: Select all

*pText = GetGadgetData(0)
SetGadgetData(0, 0)
FreeStructure(*pText)
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
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5357
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: [Solved] Set/GetGadgetData as strings

Post by Kwai chang caine »

Thanks MkSoft, i don't think to do that 8)
ImageThe happiness is a road...
Not a destination
User avatar
mk-soft
Always Here
Always Here
Posts: 5409
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: [Solved] Set/GetGadgetData as strings

Post by mk-soft »

To avoid memory leak...

Code: Select all

Procedure FreeGadgetWithData(Gadget)
  Protected *mem
  If IsGadget(Gadget)
    *mem = GetGadgetData(Gadget)
    If *mem
      FreeStructure(*mem)
    EndIf
    FreeGadget(Gadget)
  EndIf
EndProcedure
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
Post Reply