Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Passing variables to functions (BYREF / BYVAL)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Passing variables to functions (BYREF / BYVAL)

    I recently did some testing regarding variable passing and was a bit surprised at the following:

    PASSING VARIABLES TO FUNCTIONS:

    BY default, changes to SHARED variables (passed to functions via parameters) are not seen by the calling script. ~ BUT: If SHARED variables (declared in the main script) are changed inside a function (without being passed to that function via parameters) the changes will be seen outside the function. Because of this, it seems like shared variables are very risky to use in terms of debugging.

    Also, when passing pointers to functions (via parameters) I cannot figure out how to pass pointers using a "BYVAL equivalent", with the exception of passing each element separately via individual parameters. (See notes at bottom.) ~ There must be some other/better way to do this?

    In these regards, using functions apparently does little to help you isolate code! I've spent some time trying different code and techniques using the insight from the CSDA website but thus far haven't come up with anything to addressing these potential issues.
    FYI: Here are some of the tests I did/confirmed:
    SHARED variables ARE changed in calling script (unless sent to fn by parameter)
    SHARED variables passed BYVAL ARE NOT changed in calling script.
    SHARED variables passed UNSPECIFIED ARE NOT changed in calling script!
    SHARED variables passed BYREF ARE changed in calling script.

    LOCAL variables passed BYREF ARE changed in calling script.
    LOCAL variables passed UNSPECIFIED ARE NOT changed in calling script?


    Notes:
    SHARED: This is the minimum scope needed for functions to see (non-passed parameters) from calling scripts.
    *BYREF & BYVAL: These declarations are ignored when passing a pointer (even user declared pointer variables) as parameters.
    SHARED VARIABLES declared within the function are available outside the function after function is called.
    GLOBAL and LOCAL (script embedded) functions appear to behave identical in terms of parameters and variable usage.
    If a variable is declared as type SHARED (in the calling script), you are not forced to pass it into the function via parameters. ~ Potential for disaster.

    PS: I have not yet tested the behavior of arrays in the context of this thread. I suspect they may behave similarly to pointers?
    Last edited by SNusa; 01-04-2013, 03:14 PM.
    Robert T. ~ "I enjoy manipulating data... just not my data."
    It's all about the "framework." (I suppose an "a5-induced" hard drive crash is now in order?)
    RELOADED: My current posting activity here merely represents a "Momentary Lapse Of Reason."

    #2
    Re: Passing variables to functions (BYREF / BYVAL)

    Robert you are probably right.
    Knowing the fundamentals as you have uncovered is key to avoid the potential disasters.

    My comment is really about that what you describe is not peculiar to Alpha
    I cut my teeth with UDFs in the real early Clipper Circa 1985 that defined in the help (all 12 pages, (not really 12!!)) that variables passed were only by value even if the function re-used the variable name, and any variables visible by scope would retain any changes. This was embedded so that various derivatives and language I used thereafter with UDFs, I continued with that assumption - no experimentation. AS I do still with Alpha.

    Maybe thats why no long discussions on this appear on the board.

    But good spotting, just keep within the lines. No harm shall befall he who does it seems.
    Last edited by Ray in Capetown; 01-04-2013, 04:49 PM.

    Comment


      #3
      Re: Passing variables to functions (BYREF / BYVAL)

      Hi Robert,

      You don't really have it correct. Most of what you said is correct in it's effect, but it seems like you are missing what's really happening.

      Any variables (with values) in a function call are passed by value, meaning a copy of the current value at the time of the call is given to the function. Calling with a parameter like POINTER1.VALUE1 is just that specific value in the POINTER1 variable space, and is not passing the pointer. The exception is if you have the function parameter defined as a BYREF.

      Pointers of any type (pointers, arrays, collections, sub pointers like POINTER1.POINTER2) are not a value, but are a pointer to an area of values or sub-pointers, and are always BYREF, whether specified or not. If it is a pointer, you can add sub-pointers, sub-values, as well as DELETE the pointer.

      If you call a function with a variable (value, not pointers) that is defined in the function parameter as BYREF, then that variable (in the context of the calling code's search for it's scope (local, then shared, then global) is the one that will be passed, and can be changed by the function (but it's important to remember that the function searches for a DIMed (implicitly or explicitly) variable at it's local, then shared, then global as well.

      All parameter names in the function definition are local (and are implicitly DIMed, whether you want it or not). Null_Value()/Type Z/AS A, are essentially a catch all DIM until DIMed a specific type.

      Thus if you have in your function a DIMed (implicitly or explicitly) local name VAR1 and a SHARED VAR1 from the calling code, the local VAR1 has precedence, unless overridden by a WITH/END WITH or with a pointer to the shared space, as in SESSION_VARIABLES().VAR1

      To minimize confusion (read that as code mistakes) as to what scope a variable is being referenced at, a good naming scheme is recommended and can separate them, as in VAR1_G, VAR1_S, VAR1_L for global, shared (session) and local names.

      And the only difference between a global Function and a function inside some code (internal function), is that the internal one is only accessible within the context of that code running
      Regards,

      Ira J. Perlow
      Computer Systems Design


      CSDA A5 Products
      New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
      CSDA Barcode Functions

      CSDA Code Utility
      CSDA Screen Capture


      Comment


        #4
        Re: Passing variables to functions (BYREF / BYVAL)

        Great explanation Ira
        Thanks

        Comment


          #5
          Re: Passing variables to functions (BYREF / BYVAL)

          Originally posted by csda1 View Post
          ...Most of what you said is correct in it's effect, but it seems like you are missing what's really happening.
          Hi Ira. I came to the same conclusions. (After thoroughly reviewing your tips page, again.) ~ Thank you for your response! I was hoping you'd "chime in!" (I thought I was still missing something here regarding functions & "variable isolation.")
          Last edited by SNusa; 01-07-2013, 12:26 AM.
          Robert T. ~ "I enjoy manipulating data... just not my data."
          It's all about the "framework." (I suppose an "a5-induced" hard drive crash is now in order?)
          RELOADED: My current posting activity here merely represents a "Momentary Lapse Of Reason."

          Comment

          Working...
          X