Is variable or property an array?

When validating a function, procedure or method parameters, it's sometimes necessary to determine if passed parameter is an array. Until VFP 9.0 there was no obvious way to do that.


In VFP 9.0 the TYPE() function accepts additional second parameter 1, to determine if passed expression is an array, a collection or neither. In previous VFP version we can use the TYPE() function in combination with ALEN() function.

$SAMPLECODE$

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
* VFP 9.0
IF TYPE("SomevariableOrProperty",1) = "A"
  * It's array   
ENDIF

* VFP 8.0 and earlier  
IF TYPE("ALEN(SomevariableOrProperty)")) = "N"
  * It's array
ENDIF 

A check TYPE("SomevariableOrProperty[1]") = "N"

doesn't work for VFP intrinsic properties. It incorrectly returns 'N' for all of them.

1
2
3
4
5

loForm = CREATEOBJECT("Form")
? TYPE("loForm.Top[1]")            && Returns N
  

Comments