Powerbuilder 动态阵列操作

标签 powerbuilder upperbound

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/

相关文章:

powerbuilder:将下拉数据窗口与其父窗口链接

c++ - 如何使用 lower_bound(upper_bound) 查找数组中任意数字的位置?

algorithm - 写成[(m + n)^m]/m有效吗!作为 O([n/m]^m) 作为其宽松的上限?

c++ - 需要将 for 循环的上限保存在额外的变量中吗?

Powerbuilder 语言文档

file - 检查文件是否从另一个进程打开

powerbuilder:更改焦点时不会触发 itemchanged 事件

sql-server - 如何在 PowerBuilder Classic 12.5.2 中连接到 SQL Server 2016?