07-24-2005, 10:45 PM
No. Nonono.
There are two ways to pass primitive types (integers, singles, doubles, etc): Byref and Byval. Byref works by passing pointers, so you can pass UDTs (Type structures) this way as well.
However, strings and arrays organize their data with "descriptors", that is, UDTs containing information about the string/array, plus a pointer to the actual data. This is what gets passed when you say:
TestSub array()
...So Byref array() is not allowed because there's more information than what's contained in the data's pointer. This is also why you need to use something like strptr() to get a string's pointer. As proof, here's how you get a string's pointer and length without using strptr or len:
So what gets passed to the sub is actually a type structure. You can write routines handling FB arrays in other languages by having them pass this type structure:
So you see, what gets passed when you pass an array is not byref or byval. It's by-descriptor. In recent versions of FB you can pass strings byval, but I think FB just copies the string and passes the new one byref.
There are two ways to pass primitive types (integers, singles, doubles, etc): Byref and Byval. Byref works by passing pointers, so you can pass UDTs (Type structures) this way as well.
However, strings and arrays organize their data with "descriptors", that is, UDTs containing information about the string/array, plus a pointer to the actual data. This is what gets passed when you say:
TestSub array()
...So Byref array() is not allowed because there's more information than what's contained in the data's pointer. This is also why you need to use something like strptr() to get a string's pointer. As proof, here's how you get a string's pointer and length without using strptr or len:
Code:
Type FBSTRING
Data as Byte Pointer
Len As Integer
Size As Integer
End Type
Dim Bob as String
Dim BobDesc as FBSTRING Pointer
Bob = "Hello, my name is bob"
BobDesc = @Bob
Print BobDesc->Data
Print Strptr(Bob)
Print BobDesc->Len
Print Len(Bob)
So what gets passed to the sub is actually a type structure. You can write routines handling FB arrays in other languages by having them pass this type structure:
Code:
Type FBArrayDim
Elements As Integer
LBound As Integer
UBound As Integer
End Type
Type FBArray
Data As Any Pointer
Ptr As Any Pointer
Size As Integer
Element_Len As Integer
Dimensions As Integer
DimTB(1) As FBArrayDim
End Type
So you see, what gets passed when you pass an array is not byref or byval. It's by-descriptor. In recent versions of FB you can pass strings byval, but I think FB just copies the string and passes the new one byref.