Announcement

Collapse
No announcement yet.

Help on AS ANY in DECLARE SUB

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

  • Help on AS ANY in DECLARE SUB

    I think i' m missing the right way to use ANY (PB35 Reference Guide, p. 83 bottom). I never used it before.
    I' m getting a compilation error
    ("Error 481: Parameter mismatch - may need ByCopy") on the SUB statement.

    I hope someone can point me to the error.

    $DIM ALL

    TYPE TypeRecord

    zName AS STRING * 10
    zCode AS INTEGER

    END TYPE

    DECLARE SUB Proc(RecordParam AS ANY)

    END


    SUB Proc(RecordParam AS TypeRecord) PUBLIC

    PRINT "RecordParam.zName="; RecordParam.zName
    PRINT "RecordParam.zCode="; RecordParam.zCode

    END SUB

    ------------------

  • #2
    Davide --

    Two things...

    You are declaring the parameter AS ANY, but the SUB definition says AS TypeRecord. Those things are not the same, so the compiler is complaining that the parameters do not match.

    Also, the PB/DOS Help File says this in the DECLARE topic...

    "Variables passed as ANY to a SUB or FUNCTION cannot be addressed by name except using assembler."

    What are you trying to accomplish by using AS ANY?

    -- Eric


    ------------------
    Perfect Sync: Perfect Sync Development Tools
    Email: mailto:[email protected][email protected]</A>



    [This message has been edited by Eric Pearson (edited January 19, 2001).]
    "Not my circus, not my monkeys."

    Comment


    • #3
      I was trying to write a DECLARE SUB Proc(..) that allows me to call Proc without knowing its parameters, while Proc itself knows them.

      This is for a case when Proc is in another compiled Unit and i don' t know the data type of its parameters (just how many), and i' m not interested in passing values or getting return values, just interested in making Proc to execute.

      However the alternatives are not missing with PB/DOS, so i better discard this.

      In any case, just to know it, does ANY make sense only if used with assembler?

      ------------------

      Comment


      • #4
        One alternative would be to pass a single DWORD parameter, which would be a pointer to a data structure. Like this pseudo-code...

        Code:
        SUB MyFunc(BYVAL dwPointer AS DWORD)
         
        END SUB
         
        CALL MyFunc(VARPTR(RecordParam))
        As long as you always used VARPTR or STRPTR (as appropriate) to obtain a pointer to the data that you want to pass to the SUB, and you pass that pointer instead of passing the actual value, you can pass anything you want to the SUB.

        Of course, the SUB would need to get the data that is pointed-to by the pointer, and place it in a structure so that it could use it.

        Since PB/DOS supports @pointers, this wouldn't be too difficult to do. Sorry I don't have time to whip up an example...

        -- Eric


        ------------------
        Perfect Sync: Perfect Sync Development Tools
        Email: mailto:[email protected][email protected]</A>
        "Not my circus, not my monkeys."

        Comment

        Working...
        X