Alpha Video Training
Results 1 to 3 of 3

Thread: Optional Dot-Variable Parameter

  1. #1
    Member
    Real Name
    Blake Watson
    Join Date
    Jan 2003
    Posts
    961

    Default Optional Dot-Variable Parameter

    I want to allow, but not force, clients of a function I have written to pass a dot-variable (pointer) parameter.

    I can figure out if they've passed an empty dot-variable with enum_properties but there seems to be no IsNull() or Null_Value for a dot-var. There's no "void". I've tried various shenanigans, and one actually seems to work:


    function voidpointer as p()
    end function


    I can use this like so:


    function vp as v(parm = voidpointer() as p)
    if properties_enum(parm) = "" then
    ui_msg_box("VOID!" , "Sorry, Tennessee!")
    end if
    end function


    My only concern: Is it safe? Is there a more obvious approach? (As with the previous scoping issue, I know I've read a lot more on dot-variables than I can recall, and in reviewing the material I may have missed something.)

    Thanks!

  2. #2
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,299

    Default RE: Optional Dot-Variable Parameter








    New Page 1




    the key to the function is setting the default value for the function
    parameter to null_value().
    here is how you would define the function:

    function foofunc as p (param
    = null_value())
    'shows how a function can have either no argument or an optional pointer
    argument
    if typeof(param) = "P" then
    ui_msg_box("Properties of input parameter",
    properties_enum(param))
    else if typeof(param) = "Z"
    ui_msg_box("","User did not pass in any parameters to the
    function")
    'note: typeof(param) will return "Z"
    else
    ui_msg_box("","This function expects either a Pointer
    argument, or no argument at all. You have specified a " + typeof(param) + "
    argument")
    end if

    end function


    now from the interactive window:
    p.name = "fred"
    p.city = "boston"

    foofunc(p)
    foofunc()
    foofunc(23)

  3. #3
    Member
    Real Name
    Blake Watson
    Join Date
    Jan 2003
    Posts
    961

    Default RE: Optional Dot-Variable Parameter

    Selwyn,

    Thanks!

    I missed that because:


    dim ptr as p
    ptr = null_value()
    ERROR: variable type mismatch


    yet, that problem doesn't occur in this case:

    function VorR as L(ptr = null_value() as p)

    Just a note: you left off the parameter type in your example--which works!! Type is inferred from the initial value?

Similar Threads

  1. Skip parameter in UDF
    By Bill Parker in forum Archived Wishlist
    Replies: 5
    Last Post: 03-11-2006, 09:39 AM
  2. Word to the wise..Optional is not optional
    By G Gabriel in forum Alpha Five Version 6
    Replies: 8
    Last Post: 08-16-2005, 08:29 AM
  3. Suggestion: Error on misuse of optional parameter
    By Blake in forum Alpha Five Version 6
    Replies: 0
    Last Post: 08-03-2005, 07:09 AM
  4. Function Parameter calling bug?
    By csda1 in forum Alpha Five Version 5
    Replies: 0
    Last Post: 07-29-2004, 10:48 AM
  5. Bad parameter?
    By Reese Fletcher in forum Alpha Five Version 4
    Replies: 2
    Last Post: 10-17-2001, 04:30 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
  •