It is currently Thu Sep 24, 2020 3:02 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: [Solved] Set/GetGadgetData as strings
PostPosted: Tue Mar 10, 2020 1:30 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1004
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.

Top
 Profile  
Reply with quote  
 Post subject: Re: Set/GetGadgetData as strings
PostPosted: Tue Mar 10, 2020 3:57 am 
Offline
Addict
Addict

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3914
Location: Berlin, Germany
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.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Set/GetGadgetData as strings
PostPosted: Tue Mar 10, 2020 4:07 am 
Offline
Addict
Addict

Joined: Thu Apr 18, 2019 8:17 am
Posts: 1004
Good point, Little John!


Top
 Profile  
Reply with quote  
 Post subject: Re: [Solved] Set/GetGadgetData as strings
PostPosted: Tue Mar 10, 2020 9:55 am 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2656
Location: Germany
For remember
Code:
*pText.String = AllocateStructure(String)
*pText\s = "Hello World!"
Debug *pText\s
FreeStructure(*pText)

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: [Solved] Set/GetGadgetData as strings
PostPosted: Wed Mar 11, 2020 11:41 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4704
Location: Lyon - France
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: [Solved] Set/GetGadgetData as strings
PostPosted: Wed Mar 11, 2020 5:36 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2656
Location: Germany
Kwai chang caine wrote:
Code:
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:
*pText = GetGadgetData(0)
SetGadgetData(0, 0)
FreeStructure(*pText)

_________________
My Projects ThreadToGUI / OOP-BaseClass / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
 Post subject: Re: [Solved] Set/GetGadgetData as strings
PostPosted: Wed Mar 11, 2020 6:57 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 4704
Location: Lyon - France
Thanks MkSoft, i don't think to do that 8)

_________________
ImageThe happiness is a road...
Not a destination


Top
 Profile  
Reply with quote  
 Post subject: Re: [Solved] Set/GetGadgetData as strings
PostPosted: Wed Mar 11, 2020 7:16 pm 
Offline
Addict
Addict
User avatar

Joined: Fri May 12, 2006 6:51 pm
Posts: 2656
Location: Germany
To avoid memory leak...
Code:
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 / OOP-BaseClassDispatch / EventDesigner V3
PB v3.30 / v5.70 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 14 guests


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye