ProcedureReturn Limitation

Everything else that doesn't fall into one of the other PB categories.
User avatar
GeoTrail
Addict
Addict
Posts: 2794
Joined: Fri Feb 13, 2004 12:45 am
Location: Bergen, Norway
Contact:

Post by GeoTrail »

How about d|e|f then you could just parse it as a string hehehe
I Stepped On A Cornflake!!! Now I'm A Cereal Killer!
gnozal
PureBasic Expert
PureBasic Expert
Posts: 4229
Joined: Sat Apr 26, 2003 8:27 am
Location: Strasbourg / France
Contact:

Post by gnozal »

Kaeru Gaman wrote:gnozals solution has one little weakness:
the return-struct is static, so it will stay inside the procedure.
he is just assigning a structured pointer to it.
I know, I was just answering his question : how to procedure return several parameters.
And without static it will not work (unless global).
Kaeru Gaman wrote:for WinAPI calls that need a structured return,
you create your structured variable before the call and pass it's pointer to the routine.
Yes, that's how I usually do it.
For free libraries and tools, visit my web site (also home of jaPBe V3 and PureFORM).
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

I know, I was just answering his question
I know you knew, I was just giving additional information to let him avoid mistakes. ;)
oh... and have a nice day.
User avatar
pdwyer
Addict
Addict
Posts: 2813
Joined: Tue May 08, 2007 1:27 pm
Location: Chiba, Japan

Post by pdwyer »

I like the way they do it in the winAPI, it makes things kind of standard.

The return value doesn't pass data back, generally it is for passing an error/success code or a handle of some kind. If there are structures to be passed back then these are filled into pointers that clients pass them, if there's too much to pass back then its usually a handle then you use that handle to get more data.

Procedure.l MyFunct(In_Data1.l, In_Data2.l, Out_Data1.l Out_Data2.l ) ...etc

Consider this one: http://msdn2.microsoft.com/en-us/library/aa370654.aspx

Code: Select all


The NetUserGetInfo function retrieves information about a particular user account on a server.

NET_API_STATUS NetUserGetInfo(
  LPCWSTR servername,
  LPCWSTR username,
  DWORD level,
  LPBYTE* bufptr
);

Parameters

servername
[in] Pointer to a constant string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this parameter is NULL, the local computer is used.
Windows NT: This string must begin with \\.

username

[in] Pointer to a constant string that specifies the name of the user account for which to return information. For more information, see the following Remarks section.

level

[in] Specifies the information level of the data. This parameter can be one of the following values.

bufptr

[out] Pointer to the buffer that receives the data. The format of this data depends on the value of the level parameter. This buffer is allocated by the system and must be freed using the NetApiBufferFree function. For more information, see Network Management Function Buffers and Network Management Function Buffer Lengths.

Return Value

If the function succeeds, the return value is NERR_Success.

If the function fails, the return value can be one of the following error codes.
If it's good enough for the win32api, it's good enough for me :D
Paul Dwyer

“In nature, it’s not the strongest nor the most intelligent who survives. It’s the most adaptable to change” - Charles Darwin
“If you can't explain it to a six-year old you really don't understand it yourself.” - Albert Einstein
User avatar
electrochrisso
Addict
Addict
Posts: 989
Joined: Mon May 14, 2007 2:13 am
Location: Darling River

Post by electrochrisso »

Hey thanks for all the feedback.
I dusted of some of my old computer books and found out that in Qbasic you can pass values by address. Same as using pointers and the such in Pure Basic. This seems to be the best way for Pure Basic, so it would only be a convenience to be able to return more values in Pure Basic.

Amiga Basic does the way in the example below, which brings up the point of interpreted and compiled, Amiga Basic was interpreted and I am not sure if the compilers that were made for it would do it either. So perhaps this sort of thing was only included in a few offerings.

Example of Amiga Basic Two Way value Passing

Code: Select all

SUB Example (x%,y,z$) STATIC
  x%=x%+2
  y=y*5
  z$=z$+" Example"
END SUB

x%=1.5 : y=5 : z$="SUB"
Call Example (a%,b,c$)
a% ;now=3.5
b  ;now=25
c$ ;now=SUB Example
Anyway I had a lot of fun learning about structures and pointers and also found a DataSection also works well.

Code: Select all

Procedure Testing(temp1,temp2)
temp1=10:temp2=20
*temp3=@temp1
*temp4=@temp2
PokeL(?mydata,temp2)
EndProcedure
Testing(5,5)
Debug PeekL(?mydata+4)
;Debug *temp4

DataSection
  mydata:
  Data.l 0,55
EndDataSection
Enough about ProcedureReturn and Pure Basic is still the best.

Below is the code I am working on to latch the gadget in two states, so if the mouse pointer enters or leaves a gadget it does not keep on updating until the state changes to eliminate the flicker. It works good as in the example below, but I want to move the last four If statements out of the procedure so I can use it as a library. I have tried all sorts of things, but I am having a bit of trouble with the logic (my logic not working), thats why I wanted to pass two values back, have tried that now using various methods Global, Structures, Strings to no avail. I will eventually work it out and any suggestions would also be welcome.

Code: Select all

Procedure MouseOverFontChange(Button,StatusText.s,temp1,temp2)
  If IsMouseOver(Button)
    If temp1<>1
      StatusBarText(#StatusBar_Window_0,0,StatusText,#PB_StatusBar_BorderLess)
      SetGadgetFont(Button,FontID(2))
      temp1=1
    EndIf
    temp2=0
  EndIf
  If Not IsMouseOver(Button)
    If temp2<>1
      StatusBarText(#StatusBar_Window_0,0,"",#PB_StatusBar_BorderLess)
      SetGadgetFont(Button,FontID(1))
      temp2=1
    EndIf
    temp1=0
  EndIf
  If Button=#Button_0:ButtonIndex(0,0)=temp1:ButtonIndex(0,1)=temp2:EndIf
  If Button=#Button_1:ButtonIndex(1,0)=temp1:ButtonIndex(1,1)=temp2:EndIf
  If Button=#Button_2:ButtonIndex(2,0)=temp1:ButtonIndex(2,1)=temp2:EndIf
  If Button=#Button_3:ButtonIndex(3,0)=temp1:ButtonIndex(3,1)=temp2:EndIf
EndProcedure

OpenWindow_Window_0()

;{- Event loop
Repeat
  Event = WaitWindowEvent()
  MouseOverFontChange(#Button_0,"Button_0 Hover",ButtonIndex(0,0),ButtonIndex(0,1))
  MouseOverFontChange(#Button_1,"Button_1 Hover",ButtonIndex(1,0),ButtonIndex(1,1))
  MouseOverFontChange(#Button_2,"Button_2 Hover",ButtonIndex(2,0),ButtonIndex(2,1))
  MouseOverFontChange(#Button_3,"Button_3 Hover",ButtonIndex(3,0),ButtonIndex(3,1))
Last but not least a big thanks to gnozal for the brilliant jaPBe that makes it very easy to create user libs with the modified version of tailbite and all of the other things it does.
Post Reply