Poking string into a map element for stringgadget cue text?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Poking string into a map element for stringgadget cue text?

Post by Fangbeast »

The below code is normally how I poke text into a string and then set it into a string gadget to display as ghostly cue text.:

Code: Select all

Structure CueData                                                                                                                ; 
  SearchCueFont.i                                                                                                                 ; Searchbox cue font
  SearchNormalFont.i                                                                                                              ; Searchbox normal font
  SearchCueText.s                                                                                                                 ; Search box prompt text
EndStructure                                                                                                                     ; 

Global Cue.CueData                                                                                                               ; 

Cue\SearchCueFont       = LoadFont(#PB_Any,   "Georgia",       12, #PB_Font_Italic)                                               ; Empty search cue font
Cue\SearchNormalFont    = LoadFont(#PB_Any,   "Comic Sans MS", 12, 0)                                                             ; Filled cue box font
Cue\SearchCueText       = Space(256)                                                                                              ; Set the cue text buffer

PokeS(@Cue\SearchCueText, "Search for what?..", -1, #PB_Unicode)                                                                  ; Fill the buffer with the cue text

; Set initial search cue font

SetGadgetFont(#Gadget_MyAddressbook_Searchstring, FontID(Cue\SearchCueFont))

SendMessage_(GadgetID(#Gadget_MyAddressbook_Searchstring), #EM_SETLIMITTEXT, 67, 0)
SendMessage_(GadgetID(#Gadget_MyAddressbook_Searchstring), #EM_SETCUEBANNER,  1,  Cue\SearchCueText)
I am switching *Most* of my variables over to Map elements as I have discovered thanks to George Bisonte how much easier they are to use and debug especially when I can use spaces in the element key names (Great for my crappy eyesight to debug later on and I can keep element and key together!!)

Have run into a problem with poking a string into a map element and wondering if there was another way of doing this as I gather that setting a cue requires a string to be poked into a buffer and the map element does not behave like this (Like a string memory buffer?

This is how I am doing it now and get an error on the line with a poke. ANy way to fix this or is there a way around it?

Code: Select all

Structure ProgramData                                                                                                   ; 
  Map String.s()                                                                                                         ; For all string variabls
  Map Number.i()                                                                                                         ; For all integer variables
EndStructure                                                                                                            ; 

Global Program.ProgramData                                                                                              ; Declare a global map

; Search cue prompt in text boxes

Program\Number("Search cue font")       = LoadFont(#PB_Any,   "Georgia",       12, #PB_Font_Italic)                     ; Empty search cue font
Program\Number("Search normal font")    = LoadFont(#PB_Any,   "Comic Sans MS", 12, 0)                                   ; Filled cue box font
Program\String("Search cue text")       = Space(256)                                                                    ; Set the cue text buffer

PokeS(@Program\String("Search cue text"), "Search for what?..", -1, #PB_Unicode)                                        ; Fill the buffer with the cue text

Debug Program\String("Search cue text")                                                                                 ; [ERROR} Invalid memory access. (read error at address 6619219)

; SetGadgetFont(#Gadget_MyAddressbook_Searchstring, FontID(Cue\SearchCueFont))                                          ; Apply the loaded font tot he banner text

; SendMessage_(GadgetID(#Gadget_MyAddressbook_Searchstring), #EM_SETLIMITTEXT, 67, 0)                                   ; Limit the text display length of the gadget
; SendMessage_(GadgetID(#Gadget_MyAddressbook_Searchstring), #EM_SETCUEBANNER,  1,  Program\String("Search cue text"))  ; Set the cue banner text to  the gadget
Amateur Radio, D-STAR/VK3HAF
User avatar
mk-soft
Always Here
Always Here
Posts: 5406
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Poking string into a map element for stringgadget cue te

Post by mk-soft »

Is Pointer to pointer from String...

But PokeS is only for allocated memory. This can damage the string handling from PB

Code: Select all

Structure ProgramData                                                                                                   ; 
  Map String.s()                                                                                                         ; For all string variabls
  Map Number.i()                                                                                                         ; For all integer variables
EndStructure                                                                                                            ; 

Global Program.ProgramData                                                                                              ; Declare a global map

; Search cue prompt in text boxes

Program\Number("Search cue font")       = LoadFont(#PB_Any,   "Georgia",       12, #PB_Font_Italic)                     ; Empty search cue font
Program\Number("Search normal font")    = LoadFont(#PB_Any,   "Comic Sans MS", 12, 0)                                   ; Filled cue box font
Program\String("Search cue text")       = Space(256)                                                                    ; Set the cue text buffer

*ppString.integer = FindMapElement(Program\String(), "Search cue text")
If *ppString
  *pString = *ppString\i 
  If *pString
    PokeS(*pstring, "Search for what?..", -1, #PB_Unicode)  ; Fill the buffer with the cue text
  EndIf
EndIf

Debug Program\String("Search cue text")                                                                                 ; [ERROR} Invalid memory access. (read error at address 6619219)
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
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4749
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: Poking string into a map element for stringgadget cue te

Post by Fangbeast »

Thanks for that mk-soft. I don't know much about pokes etc but this is good as I use the function in various forms throughout my code and now I can replace this as well.

One bit of code after another is being replaced with maps. George showed me a good way of doing things that makes it easier to remember variables.
Amateur Radio, D-STAR/VK3HAF
Post Reply