Arrays in FoxPro

We encourage new members to introduce themselves here. Get to know one another and share your interests.
Post Reply
jpmoschi
Posts: 76
Joined: Thu May 21, 2020 3:45 pm

Arrays in FoxPro

Post by jpmoschi »

Hello forum
I continue testing in 2.6a until new advice. I know that the xsharp team is working in 2.8 to resolve arrays problems and this example try to expose in a little Probe of Concept the FoxPro capability. Please, see the comments
thanks
Juan

PRIVATE mvec1, mvec2, mvecnew
DIMENSION mvec (1,2)
DO AssignValueToVector WITH "mvec", 1,2, "hello world!!!"
? mvec(1,2)

STORE .f. TO mvecnew && all private variables must be inicialized to exist after the next line. The first value define de procedure or function owner of the variable. If you do not put this line the variable is created and disposed inside AssignValueToVector procedure
? AssignValueToVector ("mvecnew",3,2, 1234)
? mvecnew(3,2)

AssignValueToVector ( @mvec, 2 , 2, "hello" ) && function default is by val. It need @ before ref param
? mvec(2,2)

*!* DO AssignValueToVector WITH @mvecnew, 1 , 2, "VFP compiler syntax error in VFP!!!"

maux= CREATEOBJECT("myclass")
maux.methodToAssignValue(1,2,"hello")
? maux.arrayproperty(1,2)
WAIT
RETURN
****************************
PROCEDURE AssignValueToVector
PARAMETERS pvec, prow, pcol, pvalue && pvec Array passed by ref or passed name of Array defined before
if type("&pvec.(3,1)")="U" && to detects if the array is not declared correctli
IF TYPE("pvec")="C"
dimension &pvec.(3,2) && An array could change dimensions without lost the values. Pay atention: "you can use macros too"
ENDIF
ENDIF

IF TYPE("&pvec.(1,1)")<> "U"
&pvec.(prow,pcol)= pvalue && Pay atention: "you can use macros too"
ELSE
pvec(prow,pcol)= pvalue
ENDIF
RETURN
**************************************
DEFINE CLASS MYCLASS AS Custom
DIMENSION ARRAYPROPERTY (2,2)
PROCEDURE methodToAssignValue (prow,pcol,pvalue)
this. arrayproperty(prow,pcol)= pvalue
ENDDEFINE
User avatar
Chris
Posts: 4599
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Arrays in FoxPro

Post by Chris »

Juan, thanks for the sample, I see that some of those issues still exist in the 2.8 compiler and I have added this sample to our test suite. Not sure if Robert needs any clarifications on some aspects..
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
Post Reply