数组长度增加问题

Anders_lt 2008-07-04 02:54:32
一个数组 setlength 为10 ,后来想长度增加1 ,原先的数据不变,请问怎么操作?
...全文
192 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
qkhhxkj102 2008-07-06
  • 打赏
  • 举报
回复
哇,这样也可以
我以前是再定义一个数组,再复制现在有好方法了,学习了
jacknes009 2008-07-04
  • 打赏
  • 举报
回复
setlength(xx, 11)就可以啊,
原有数据会保留的
wywry 2008-07-04
  • 打赏
  • 举报
回复
var
MyArray:Array of Byte;

SetLength(MyArray, High(MyArray)+2);

MyArray[High(MyArray)]:=100;
byteh 2008-07-04
  • 打赏
  • 举报
回复
setlength(xx, High(xx)+1);

自动扩容,但要求必须是动态数组
梅青松 2008-07-04
  • 打赏
  • 举报
回复
帮助中有说明的
procedure SetLength(var S; NewLength: Integer);

Description

S is a Delphi string or dynamic-array variable.

NewLength is the new number of characters or elements in S.

For a short-string variable, SetLength simply sets the length-indicator character (the character at S[0]) to the given value. In this case, NewLength must be a value between 0 and 255.

For a long-string or dynamic-array variable, SetLength reallocates the string or array referenced by S to the given length. Existing characters in the string or elements in the array are preserved, but the content of newly allocated space is undefined. The one exception is when increasing the length of a dynamic array in which the elements are types that must be initialized (strings, Variants, Variant arrays, or records that contain such types). When S is a dynamic array of types that must be initialized, newly allocated space is set to 0 or nil.
梅青松 2008-07-04
  • 打赏
  • 举报
回复
setlength(xx, 11)就可以啊,
原有数据会保留的

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧