procedure SetLength(var S; NewLength: Integer);
解决方案 »
- delphi USB通讯
- FastReport问题一:请问在细表中有一个字段关联到另一张表中主关键字(部门ID),如何在细表中显示出显示名称?
- 在线等待~!有关问题~!
- 表操作:
- Borland专家聊天
- 曾经为爱和正在为爱痛苦的请进来
- 请哪位讲解一下delphi的一个关于sql数据库的打包过程啊?!
- 哪位大侠给解释一下呀很简单的问题
- 如何得到指定窗口中的各个控件的HWND????????
- 当用midas 用applyupdata提交的时候到底是...如果提交到一半的时候掉线了...
- 如何知道我按的是OK按钮,还是Cancel按钮
- ladies and gentleman! I have a question! Please help me!!!
错误提示:
[Error] main.pas(40): Incompatible types
VararrayCreate!!!
var
myArray : array of string;
i:integer;
begin
SetLength(myArray,20);
for i:=0 to 19 do
myArray[i]:='aaa';
end;以上程序,经过测试没问题。 再搞不掂,把你的代码贴上来。然后自打两下屁股
对不起,我的用法不是你那样的!楼上的代码一定可以的。
===========================================================
procedure my(Astr : string ;var spltstr:array of string ) ;
var
mystr : string ;
i,j : integer ;
myarr : array of string ;
begin
mystr := Astr ;
j := 0 ;
for i := 1 to length(mystr) do
begin
if mystr[i]=',' then
j := j + 1 ;
end;
setlength(myarr,j) ;
//setlength(spltstr,j) ; 直接使用时,此时就出错了 j := 0 ;
for i := 1 to length(mystr) do
begin
if mystr[i]=',' then
j := j + 1
else
myarr[j] := myarr[j]+mystr[i] ;
end;
spltstr := myarr ; //TMDTMD!!!~~~~~~~~~~^OO^~~~~~~~~~~~~~~~~
end;
------------------------------------------
Within the body of a routine, open array parameters are governed by the following rules.They are always zero-based. The first element is 0, the second element is 1, and so forth. The standard Low and High functions return 0 and Length ?1, respectively. The SizeOf function returns the size of the actual array passed to the routine.
They can be accessed by element only. Assignments to an entire open array parameter are not allowed.
They can be passed to other procedures and functions only as open array parameters or untyped var parameters. They cannot be passed to SetLength.Instead of an array, you can pass a variable of the open array parameter抯 base type. It will be treated as an array of length 1.
再把代码改成:
procedure my(Astr : string ;var spltstr:Tmyarray);
你再试试,应该可以。
好像是delphi的特性
这样子的确可以了,但是
Tmyarray 类型的数组,在使用中不知道如何做了
如 :
var
myarr : Tmyarray ;
str : string ;
i : integer ;
begin
my(str,myarr) ;
for i:=low(myarr) to high(myarr) do //此时出错了
.............
end ;
本来就是动态的string类型数组。
var
myarray:array[0..34] of string
my(str,myarr) ;
for i:=low(myarr) to high(myarr) do //此时出错了
.............
end ;
myarr没分配空间