GLBasic forum

Main forum => GLBasic - en => Topic started by: Moebius on 2012-Oct-20

Title: DGStr::GetStrData(size)?
Post by: Moebius on 2012-Oct-20
The help file under INLINE mentions this function, but whenever I try to use it the compiler tells me that "class __GLBASIC__::DGStr has no member named 'GetStrData'".
Does the help file list the wrong name?  or what should I be using here?  Thanks.
Title: Re: DGStr::GetStrData(size)?
Post by: MrTAToad on 2012-Oct-20
Yes - it is wrong as that function no longer exists.

You get the string data by using something like :

Code (glbasic) Select

char *data=m_str.c_str();


Need to update the information at some time.
Title: Re: DGStr::GetStrData(size)?
Post by: bigsofty on 2012-Oct-21
Mr T. is correct, it looks like the manual needs a little edit.  ;/
Title: Re: DGStr::GetStrData(size)?
Post by: Moebius on 2012-Oct-21
Yep it's easy get a pointer to the data, but how then do I allocate a buffer?  without GetStrData the only way I can think of getting a specific size DGStr is:
FOR i = 1 TO Size
   INC Buffer$, " "
NEXT
... which I can't see working very nicely or quickly :\

@Gernot (well anyone who knows the internal DGStr definition) is there another way I can allocate a string of a variable size?  Some special constructor?

(Slightly related, could GLB get around strings "like \0 this" by having a constructor take a c-string and a length?  That would be a lot easier than "like " + CHR$(0) + " this")
Title: Re: DGStr::GetStrData(size)?
Post by: MrTAToad on 2012-Oct-21
There is an alloc() function, which will allow you to defined a string to a set size.  I dont know what it is initialise to initially though, so you should probably not depend on anything...

In addition there is also a setlength() function (which I think is the preferable one to use).
Title: Re: DGStr::GetStrData(size)?
Post by: Moebius on 2012-Oct-21
Alright I couldn't get setlength() to work, but alloc(int,bool) does seem to work (where the second boolean parameter seems to specify whether to copy the old string across).
Thanks for that - hopefully things won't be broken by this!
Title: Re: DGStr::GetStrData(size)?
Post by: MrTAToad on 2012-Oct-21
No - the only time anything would is if __GetPrpjectVersionGLB() got renamed :)