定义了一个接收变参数组的函数,如下。
function TForm1.Recieve(const Values: array of const): string;
beginend;问题是调用得是Recieve([1,2,3]);那如何把A: array of Integer的所有元素(setlength(a,3)),一次传递给RecieveRecieve([A])是不对的,Recieve(A)也不行。
请问除了Recieve([A[0],A[1],A[2]])外,有其他的能用写法吗?因为A是动态数组。
function TForm1.Recieve(const Values: array of const): string;
beginend;问题是调用得是Recieve([1,2,3]);那如何把A: array of Integer的所有元素(setlength(a,3)),一次传递给RecieveRecieve([A])是不对的,Recieve(A)也不行。
请问除了Recieve([A[0],A[1],A[2]])外,有其他的能用写法吗?因为A是动态数组。
解决方案 »
- 问个问题。大家应该都懂的吧。
- VCLSkin4.22有Bug?
- 急!急!!急!!!,为什么我做的Service Application 只干了几秒钟的活就自动退出了??
- 高分求救--怎样使用webbrowse提取网页中类似combobox中选定的值
- access数据库的压缩问题?
- 谁能给我一个DelphiX6,在线等待.
- 各位帮帮我吧!
- 请问各位:为什么我的程序会这么慢,怎么解决?在线等,谢谢
- [李维文章推荐]DELPHI的原子世界(1)
- sender,收分了没有?俺的下个问题:如何使TDBGrid和TADOTable有反应?
- Server 2008 不能“服务于桌面交互”??
- 实现多窗体的一些问题
TIntegerArray = array of Integer;Unfortunately, this looks a lot like the syntax used for open array parameters. But they are not the same. An open array parameter will accept dynamic arrays like array of Month, but also static arrays like array[0..11] of Month.
Hope it helps.//Ali
我的意思是,A是个数组,比如我不想一个个把A的元素列在方括号内,比如Recieve([A[0],A[1],A[2]])。
因为A的长度是动态的。 我希望能把数组A的所有元素一次传给Recieve。
而不需要写成
Recieve([A[0],A[1],A[2]],....)
我想说的是:
type
TIntegerArray = array of Integer; function Receive(const Values : TIntegerArray);
begin
//可以用High和Low来循环
end;procedure test;
var
A : TIntegerArray;
begin
SetLength(A,3);
A[0] := 1;
A[1] := 2;
A[3] := 3; Receive(A) //这个应该不会有任何问题
end;
Hope it helps.//Ali
针对楼主问题,较为省力的方法就是改变函数参数为动态数组,弃用开放数组PS:当一个函数参数声明为array of const,也就相当于它声明:我不关心你传来多少参数,也不限制某个参数的具体类型,你只要在调用我之前,把要传来的数据(或数据的地址)压栈就行了。