Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / FUNCTION parameters - pass-by-value or pass-by-reference?

Author
Message
ryansobol
21
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 20th May 2003 17:05
Just for my use knowledge, are parameters of functions passed by value or passed by reference? I'm trying to use global user-defined types and I'm not sure how I can use them within a FUNCTION. I can't seem to find the answer in the DBPro manual.

Ryan
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th May 2003 20:51
Function arguments are passed by value.

If you want to access a global variable, you should define it as global :

global i as integer
ryansobol
21
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 21st May 2003 05:51
crazy... so for my next question... can variables defined as "global" be used inside a FUNCTION?

CloseToPerfect
21
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 21st May 2003 07:40
yes global is anywhere, local is local to the main code or local to the function, just be careful not to delcare a global and then try to redeclare it local in a function.
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 21st May 2003 09:29
the "global as" parameter will allow you to define simple variables as globals.


dim myarray(0) :myarray(0) = 100


arrays declared in your main file will be global by defualt but you cannot use them for parameter calls in functions unless you hand them over to a variable before the function call.

they will how ever be updated inside the function if u make a call to the function without the arrays being a parameter inside the function usage.

ryansobol
21
Years of Service
User Offline
Joined: 20th May 2003
Location:
Posted: 22nd May 2003 19:01
hmm... let me see if i understand what you are saying...

variables (as primatives or as user-defined types) defined as global can be used anywhere in your document of code like all other high level languages.

however, arrays can not be pased into a function as an argument. to get around this you can just assign a temporary variable the value of a specific index in an array and pass that variable into the function. although this is a simple solution an even simpler would be to define the array as a global and just manipute it within the function like a regular global variable.

so is that what you are trying to say?

Rob K
Retired Moderator
22
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 22nd May 2003 19:40 Edited at: 22nd May 2003 19:41
All arrays are global in DBP. You can also use

a = myfunction(myarray(1),anotherarray(2)

as arguments.

Do you want Windows menus in your DBP apps? - Get my plugin: http://snow.prohosting.com/~clone99/downloads/tpc_menus_102.zip
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 22nd May 2003 19:52
I dont know why RObK would say something thats clearly incorrect.


unfortunately you cant use arrays as argument parameters in either DBC and or DBP


consult this example to show you cant.






this example shows the global availability of an array data inside a function.

usage within a parameter will require either a hand over to a variable or a Typed Array will work as a parameter call.



this snippet does not cover using a globallly declared variable or creating a Typed array.

Login to post a reply

Server time is: 2024-09-20 09:24:01
Your offset time is: 2024-09-20 09:24:01