Announcement

Collapse
No announcement yet.

Passing string expression to function expecting BYREF ASCIIZ parameter

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

  • Passing string expression to function expecting BYREF ASCIIZ parameter

    Is there a way to directly pass a string expression to function expecting BYREF ASCIIZ parameter (without first assigning it to an ASCIIZ variable)?

    IOW, I want to pass something like PARSE$( a$, $BS, 1) to a function like FUNCTION ProcessData( szSource AS ASCIIZ) AS LONG. I know I can assign the PARSE$ to an ASCIIZ variable, but then I'm forced to impose a limitation on the size of strings that the database can hold and I'd rather not do that if possible.

    I could assign it to a STRING variable and call the function with BYVAL STRPTR( ), but I'm wondering if there is a way to bypass that assignment and use the expression directly in the function call?
    Bernard Ertl
    InterPlan Systems

  • #2
    >I could assign it to a STRING variable and call the function with BYVAL STRPTR( )..

    This is what i do yes.

    Not sure you can reuse the outcome of a function like Parse()
    hellobasic

    Comment


    • #3
      Code:
      #compile exe
      #dim all
      
      sub x ( z as asciz)
          ? z
      end sub
      '-------------------------------
      function pbmain () as long
          local s as string
          
          s = "one, two"
          x(parse$(s,2))
      
      end function

      Comment


      • #4


        For some reason, I thought that would not work. Perhaps it didn't work like that with older versions of the compiler? In any event, thanks.
        Bernard Ertl
        InterPlan Systems

        Comment


        • #5
          AFAIK, PB has always allocated a temporary fixed buffer when an ASCIIZ parameter is passed "raw data" (string literals, etc). The amount allocated is the length of the data plus one (for the NULL terminator). If an empty string is passed then you get a NULL pointer.

          You can change this buffer but it is discarded once the function is terminated and the stack gets cleaned up.
          Last edited by Kev Peel; 4 Feb 2009, 04:48 PM.
          kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

          Comment


          • #6
            For some reason, I thought that would not work. Perhaps it didn't work like that with older versions of the compiler?
            Perhaps there have been some differences across versions.

            In any case I don't think it should work, I think it should return a parameter mismatch error at compile time.

            However, I believe I am in a VERY SMALL minority with this opinion.



            MCM
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              However, I believe I am in a VERY SMALL minority with this opinion.
              Yes.
              kgpsoftware.com | Slam DBMS | PrpT Control | Other Downloads | Contact Me

              Comment

              Working...
              X