Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Changing vars, BYREF like

  1. #1

    Changing vars, BYREF like

    One thing that's not immediately clear to me how I can change the content of vars passed as a parameter calling a module defined Sub/Function.
    That is, what I want to do is something like:

    [code=thinbasic]DIM x, y, r, g, b as LONG
    x = 10
    y = 15
    TBDOG_PGET(x, y, r, g, b)[/code]

    So in the PB defined sub I want to be able to alter those r, g and b var with the actual pixel values.
    I think I have to get the token id while parsing the parameters, but a small example as a guideline will be much appreciated.

    Thanks,
    Bye!

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Changing vars, BYREF like

    Hi Mark0,

    this can be done very easily, Eros explained it in one post: please read here

    Good luck with your module !


    Bye,
    Petr
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3

  4. #4
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Changing vars, BYREF like

    Thanks Petr.

    Maybe worth to repeat here again.

    In case you need variables passed by reference, here it is an little Power Basic example on which functions to use from thinCore.dll interface to be able to change one or more variable passed byref like "dialog get client hWnd to x, y":
    [code=thinbasic]
    '---Declare needed variables. To change a variable we need
    '---a reference pointer and an aboslute position (in case of arrays)
    LOCAL lVariablePtr1 AS LONG
    LOCAL lVariableAbsPos1 AS LONG
    LOCAL eResult1 AS EXT

    LOCAL lVariablePtr2 AS LONG
    LOCAL lVariableAbsPos2 AS LONG
    LOCAL eResult2 AS EXT

    '---Check if any error
    IF thinBasic_ErrorFree THEN
    '---Get reference of first variable
    thinBasic_VariableParse(lVariablePtr1, lVariableAbsPos1)

    '---Check if comma
    IF thinBasic_CheckComma() AND thinBasic_ErrorFree THEN

    '---Get reference of second variable
    thinBasic_VariableParse(lVariablePtr2, lVariableAbsPos2)

    IF thinBasic_ErrorFree THEN

    '---Here do what you need to do


    '---Now assign values to referenced variables
    thinBasic_ChangeVariableNumberDirect (lVariablePtr1, lVariableAbsPos1, eResult1)
    thinBasic_ChangeVariableNumberDirect (lVariablePtr2, lVariableAbsPos2, eResult2)

    END IF
    END IF
    END IF
    [/code]
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  5. #5
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Changing vars, BYREF like

    ???
    TBDOG...
    What's that?
    ;D
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  6. #6

    Re: Changing vars, BYREF like

    Let's say it's just a code name! TBDW will probably be a better prefix, yeah!

    BTW, I'm having some problems getting the thinBasic_VariableParse working.
    I have noticed from the thinCore.INC that the parameters have changed, but I'm getting nothing as the var name and 1 for both the other two parameters. I'm surely doing something wrong...

    Bye!

  7. #7

    Re: Changing vars, BYREF like

    I'm surely doing something silly, so I'll appreciate if someone can point out what I'm doing wrong:

    Here's the a thinBasic test source:
    [code=thinbasic]MODULE "tBDW"

    dim res as long
    dim u as ext

    TBDW_Test(u)
    res = Msgbox(0, "U:" & str$(u))
    [/code]

    Here's PowerBASIC symbol loading:
    [code=qbasic]thinBasic_LoadSymbol "TBDW_Test", %thinBasic_ReturnNone, CODEPTR(Exec_tBDW_Test ), %thinBasic_ForceOverWrite
    [/code]

    And the actual procedure:
    [code=qbasic]SUB Exec_tBDW_Test()

    LOCAL VName AS STRING
    LOCAL VPTR AS LONG
    LOCAL VAbsPos AS LONG
    LOCAL myValue AS EXT

    IF thinBasic_CheckOpenParens() THEN
    thinBasic_VariableParse(VName, VPtr, VAbsPos)
    IF thinBasic_CheckCloseParens() THEN
    MSGBOX STR$(VPtr) & "," & STR$(VAbsPos) & ", [" & VName$ & "]", , "PowerBASIC"
    MyValue = 117
    thinBasic_ChangeVariableNumberDirect (VPtr, VAbsPos, MyValue)
    END IF
    END IF

    END SUB
    [/code]

    The PB's MSGBOX show VPTR = 1, VAbsPos = 0 and VName as large empty string, and obviously it then GPF ???


    Thanks,
    Bye!

  8. #8
    thinBasic author ErosOlmi's Avatar
    Join Date
    Sep 2004
    Location
    Milan - Italy
    Age
    57
    Posts
    8,777
    Rep Power
    10

    Re: Changing vars, BYREF like

    Marco,

    the syntax you are using for thinBasic_VariableParse is an old one.
    Current one has no VariableName to be passed:
    [code=freebasic]
    DECLARE FUNCTION thinBasic_VariableParse _
    LIB "thinCore.DLL" _
    ALIAS "thinBasic_VariableParse" _
    ( _
    BYREF VariablePtr AS LONG , _ '---ATTENTION: parameter passed BYREF will return info
    BYREF VariableAbsPos AS LONG _ '---ATTENTION: parameter passed BYREF will return info
    ) AS LONG
    [/code]

    So change your function to
    [code=thinbasic] SUB Exec_tBDW_Test

    LOCAL VPTR AS LONG
    LOCAL VAbsPos AS LONG
    LOCAL myValue AS EXT

    IF thinBasic_CheckOpenParens( ) THEN
    thinBasic_VariableParse(VPtr, VAbsPos) '---<<<<<<<<<Change here. No more var name
    IF thinBasic_CheckCloseParens( ) THEN
    MSGBOX STR$ (VPtr) & "," & STR$ (VAbsPos) & ", [" & "]", , "PowerBASIC"
    MyValue = 117
    thinBasic_ChangeVariableNumberDirect (VPtr, VAbsPos, MyValue)
    END IF
    END IF
    END SUB
    [/code]

    Just in case, please find attached latest thinCore.inc file interface.

    Let me know.

    Ciao
    Eros
    Attached Files Attached Files
    www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
    Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000

  9. #9

  10. #10

    Re: Changing vars, BYREF like

    Here is the first release.

    tBDW - thinBasic Project Dogwaffle scriptable interface

    The API implemented is minimal at the moment, but it's just what's needed to access the pixels and do a variety of filters, for example.
    Is there a more appropriate section in the forum to make a post? I looked around but I'm a bit confused about what me the better!

    Bye!

Page 1 of 3 123 LastLast

Similar Threads

  1. byref or not byref that is the question.
    By Michael Clease in forum Module SDK (Power Basic version)
    Replies: 2
    Last Post: 04-11-2010, 02:55

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

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