Alpha Video Training
Results 1 to 4 of 4

Thread: Understanding Pointers passed to a function

  1. #1
    Member
    Real Name
    Robert Adler
    Join Date
    May 2008
    Location
    Cherry Hill, NJ USA
    Posts
    129

    Default Understanding Pointers passed to a function

    As someone still relatively new to Alpha Five, I'm confused by the following code below and can't find any documentation that helps.

    I know a pointer is being passed to the function. I assume "with vars" is required to access the variables in the pointer. Each variable is then being referred to with a "v." prefix. What is the relationship between "vars" and "v." in this code?

    Some explanation would be very much appreciated.

    Bob A


    Code:
    function doValidate as l (vars as p)
    with vars 
    
    dim errorText as c = ""
    if v.customer_ID = "" then 
    	errorText = errorText + "Customer_ID cannot be blank." + crlf()
    end if
    
    if v.firstname = "" then 
    	errorText = errorText + "Firstname cannot be blank." + crlf()
    end if 
    
    if v.lastname = "" then 
    	errorText = errorText + "Lastname cannot be blank." + crlf()
    end if 
    
    if errorText = "" then
    	doValidate = .t.
    else
    	doValidate = .f.
    	errorText = "Record was not saved. Your form has errors:" + crlf() + errorText
    	?"alert('" + JSStringEncode(errorText) +  "');"
    
    end if 
    
    end with 
    end function

  2. #2
    Member Mike Thomson's Avatar
    Real Name
    Mike Thomson
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    266

    Default Re: Understanding Pointers passed to a function

    I Can't see the rest of the code but I would imagine that the pointer variables is multidimensional.

    ie: You could Have simething like

    HTML Code:
    family as P
    family.Members.Dad as C
    familiy.Members.Mum as C
    familiy.Members.Kids as C
    family.pets. Dog as C
    etc

    You can pass thid pointer to a function such as this

    Code:
    function ShowFamily (Vars as P)
    with Vars.Members
    ui_msg_box ("Dad's name is " + "Dad"
    end with
    The important things with pointers are that you are passing a referecnce to point in memory and not a seperate variable instance. This means any changes to pointer values in the function would also be returned to the calling function (a bit like BYREF).

    Does this help?
    Last edited by Mike Thomson; 07-18-2008 at 10:22 AM.
    Mike Thomson

  3. #3
    Member
    Real Name
    Robert Adler
    Join Date
    May 2008
    Location
    Cherry Hill, NJ USA
    Posts
    129

    Default Re: Understanding Pointers passed to a function

    Thanks Mike. Then "v" must be a child pointer under "vars" and not another way of referencing "vars". That's what had me confused.

    Bob

  4. #4
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: Understanding Pointers passed to a function

    Hi Bob,

    Quote Originally Posted by boba View Post
    Thanks Mike. Then "v" must be a child pointer under "vars" and not another way of referencing "vars". That's what had me confused.
    New variables are created under the "vars" space within the WITH/END WITH unless explicitly dimensioned at another level.

    Other variables, such as v.xxxx are looking in the "vars" space 1st, but will also search higher levels (such as session, layout, global and addin) for a variable called v.xxxx.

    This is why all local uses must be Dim'ensioned to be sure of their locality within a function. See my tips page here on variable dimensioning and usage.
    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



Similar Threads

  1. Username and Password passed from ASP
    By Walter in forum Application Server Version 8
    Replies: 12
    Last Post: 07-10-2007, 05:38 AM
  2. What happens when DB Maximum is passed
    By mronck in forum Alpha Five Version 7
    Replies: 4
    Last Post: 07-01-2006, 10:53 AM
  3. Values Not passed to next window
    By Willard in forum Web Application Server v6
    Replies: 3
    Last Post: 12-06-2004, 06:34 AM
  4. Function returning pointers
    By michaelklein in forum Alpha Five Version 5
    Replies: 13
    Last Post: 04-30-2004, 07:51 AM
  5. Can a variable be passed
    By Barry Potter in forum Alpha Five Version 4
    Replies: 6
    Last Post: 09-21-2000, 07:51 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •