Python4Delphi EvalFunction with var Parameters

250 views
Skip to first unread message

René Troxler

unread,
Feb 5, 2021, 7:05:59 PM2/5/21
to PyScripter
Is it possible to call a pyton function using EvalFunction and passing a variable as var parameter?

Example Python Code:

def finditem( name: string, index: int) -> bool:
    for ....:
        if (blbla):
            index = position
            return(True)
    return false

I'd like to call this function from delphi, passing a variable of type integer to the parameter index.
After calling this function I would like to retrieve the respectibe index from that variable.
It did many test with passing pointer of an integer value in the args array, casting it with NativeInt and so on...

Nothing worked.

Could someone give me an advice?
Thanks in adnavance

PyScripter

unread,
Feb 6, 2021, 9:55:01 AM2/6/21
to PyScripter
python does not have var parameters.  You can return a tuple instead with all values required.

René Troxler

unread,
Feb 7, 2021, 4:52:45 PM2/7/21
to PyScripter
Thank you for that answer. 
Actually, the problem is, that i need to get back some multi dim arrays from the function.
Because arrays are emutable, this works in python (they are passed by ref)
Ok. It did not work in python4delphi EvalFunction.

Next, i tried to return at least one multi dimensional array in a function like below:
     twodimarray = [[0]*10]*2
     twodimarray[0][0] = 111.123
     return(twodimarray)

This did neither work. I receive an variant array but it seems to be empty
So, what do I need to do to get back this array when calling EvalFunction?

PyScripter

unread,
Feb 7, 2021, 5:37:58 PM2/7/21
to PyScripter
What you are getting back is not a variant array, it is a Python object  representing the list object,  wrapped in a custom variant.
If V is the result you can do something like
V.GetItem(0).GetItem(0)

PyScripter

unread,
Feb 7, 2021, 5:39:56 PM2/7/21
to PyScripter
And by the way this the PyScripter forum and not the Python4Delphi one.  Please ask such questions at  Forums - Delphi-PRAXiS [en]   

René Troxler

unread,
Feb 8, 2021, 4:00:19 PM2/8/21
to PyScripter
Inspite of being in the wrong forum, thanks anyway. Tought the product is from pyscripter... my fault.
Reply all
Reply to author
Forward
0 new messages