how to set attribute for IUP according to numerical value?

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

how to set attribute for IUP according to numerical value?

Post by oyster »

maybe this is a "how to covert string to zstring ptr" question?

in the following simple code which use the IUP GUI lib, I use IupSetAttribute who has a delcaration in "FreeBASIC-1.05.0-win32\inc\IUP\iup.bi" as

Code: Select all

declare sub IupSetAttribute(byval ih as Ihandle ptr, byval name as const zstring ptr, byval value as const zstring ptr)
if I write

Code: Select all

IupSetAttribute(dlg, "TITLE", "600")
then the title is set to 600 as expected; but if I write

Code: Select all

IupSetAttribute(dlg, "TITLE", str(wid))
, then the title is not set to 600 but a questionnaire mark( i.e. "?"). I know we can write

Code: Select all

  dim as string t = str(wid)
  IupSetAttribute(dlg, "TITLE", t) 
or (please note it is IupSetfAttribute, not the above IupSetAttribute)

Code: Select all

  IupSetfAttribute(dlg, "TITLE", "%d", wid) 
but I prefer to fix and use the simple way

Code: Select all

IupSetAttribute(dlg, "TITLE", str(wid))
,and I think I will meet this similar question in other lib. So the question is why `str(wid)` does not work here as the FreeBasic says "a string will be auto cast to zstring ptr during function/sub call"? how to fix it? thanks

Code: Select all

#include once "IUP/iup.bi"

Function main() as Integer
  Dim as Ihandle ptr dlg, button,vbox
  dim wid as integer= 600  ' this value maybe calculated by some function, so I don't know its string format in advance

  IupOpen(0, 0)
  button = IupSetAttributes(IupLabel("I'm a label"), "SIZE=100x")
  vbox = IupVbox(button, 0)

  dlg = IupDialog(vbox)
  ' ~ IupSetAttribute(dlg, "TITLE", "600")  ' this works
  IupSetAttribute(dlg, "TITLE", str(wid)) ' this set title to questionary mark

  IupShowXY(dlg, IUP_CENTER, IUP_CENTER)
  IupMainLoop()
  IupClose()
  return 0  'EXIT_SUCCESS
End Function

main()
WQ1980
Posts: 48
Joined: Sep 25, 2015 12:04
Location: Russia

Re: how to set attribute for IUP according to numerical value?

Post by WQ1980 »

oyster

Code: Select all

IupSetStrAttribute
?

http://webserver2.tecgraf.puc-rio.br/iup/
-> IupSetAttribute
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

Re: how to set attribute for IUP according to numerical value?

Post by oyster »

WQ1980 wrote:oyster

Code: Select all

IupSetStrAttribute
?

http://webserver2.tecgraf.puc-rio.br/iup/
-> IupSetAttribute
no, no. IupSetAttribute needs the attribute's value to be a string. I am asking why str(600) can not be used directly
fxm
Moderator
Posts: 12083
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: how to set attribute for IUP according to numerical value?

Post by fxm »

'str()' returns a temporary string (can be checked by testing 'strptr(str())' that induces a compiler error).
'IupSetAttribute()' internally stores the value pointer, so only static values must be used.

In that specific case (when passing temporary strings), perhaps you can try to use 'IupStoreAttribute()' which duplicates the attribute.
Post Reply