return wide string from function?

General FreeBASIC programming questions.
Post Reply
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

return wide string from function?

Post by oyster »

In my function, a wide string is returned by calculating the parameter. but
```
Function routine(array() As Integer) As WString
do something
End Function
```
says
```
a.bas(1) error 28: Expected pointer in 'Function routine(array() As Integer) As WString'
```

so how to fix it? Thanks
zmymhlej
Posts: 11
Joined: Mar 23, 2022 16:50

Re: return wide string from function?

Post by zmymhlej »

wstring ptr?
fxm
Moderator
Posts: 12203
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: return wide string from function?

Post by fxm »

You can return a WString (or a ZString) from a function only by pointer or by reference:
Function routine(array() As Integer) As ZString Ptr
or
Function routine(array() As Integer) Byref As ZString
Xusinboy Bekchanov
Posts: 805
Joined: Jul 26, 2018 18:28

Re: return wide string from function?

Post by Xusinboy Bekchanov »

You can also return your self-written UString type like this (строка 369):
https://github.com/XusinboyBekchanov/My ... g.bas#L369

ZString Ptr has a String type, but WString Ptr has no such type. There are many implementations of this type on this forum: DWString, CWStr, UString and etc.
dodicat
Posts: 7999
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: return wide string from function?

Post by dodicat »

I don't know if this will work in your location oyster.

Code: Select all


shell "CHCP 65001"
cls

Function routine(array() As Integer) As WString ptr
static as wstring * 100 p
var q=!"\x53\x69\x7a\x65\x20\x6f\x66\x20\x74\x68\x65\x20\x61\x72\x72\x61\x79\x20\x3d\x20"
p= q+wstr(ubound(array)-lbound(array)+1)
return @p
End Function

function finish() as wstring ptr
static as wstring * 100 f=!"\x50\x72\x65\x73\x73\x20\x61\x6e\x79\x20\x6b\x65\x79\x20\x74\x6f\x20\x66\x69\x6e\x69\x73\x68\x20\x2e\x20\x2e\x20\x2e"
return @f
end function

dim as integer b(1 to 400)
print *routine(b())
print *finish()

sleep



 
oyster
Posts: 274
Joined: Oct 11, 2005 10:46

Re: return wide string from function?

Post by oyster »

thank you guys
Post Reply