string array[]
long lBound, uBound
lBound = LowerBound(array[]) // = 1, empty array value
uBound = UpperBound(array[]) // = 0, empty array value
array[1] = 'Item 1'
array[2] = 'Item 2'
array[3] = 'Item 3'
lBound = LowerBound(array[]) // = 1
uBound = UpperBound(array[]) // = 3
array[3] = '' //removing item 3
lBound = LowerBound(array[]) // = 1, still
uBound = UpperBound(array[]) // = 3, still (but array[3] is nulled?
我认为“array[3]”行是错误的,但我认为我已经读过这应该删除数组单元格。
删除数组单元格的正确方法是什么?它取决于对象类型吗? (字符串 vs 数字 vs 对象)
或者
可以操纵 UpperBound 值使其工作吗?
即删除项目 3 后,我希望 UpperBound 或数组长度为 2,因为这在逻辑上是正确的。
最佳答案
For variable-size arrays, memory is allocated for the array when you assign values to it. UpperBound returns the largest value that has been defined for the array in the current script .但是,您可以使用另一个动态数组来解决这个问题。
string array2[]
int i
for i = 1 to UpperBound(array[]) - 1
array2[i] = array[i]
next
array = array2
然后 UpperBound(array[]) 将减少 1。
这将适用于 UpperBound(array[]) - 1 > 2 因为 powerbuilder 在声明动态数组时默认为 3 个元素分配内存大小。
关于Powerbuilder 动态阵列操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2536015/