我想作个给数组赋值的过程,可以这样调用:var
myArray:array of string;
pathstr:string;
begin
pathstr='c:\test';
SetDirectName(myArray,pathstr);
showmessage(length(myArray));
end;procedure tform1.SetDirectName(dst1:array of String ; PathName : String);
var
i:integer;
j:integer;
sr:Tsearchrec;
begin
i:=0;
j:=0;
i:=findfirst(pathname+'*.*',faanyfile,sr);
while i=0 do
begin
if (sr.name<>'.') and (sr.name<>'..') and (sr.Attr>=16) and (sr.attr<=17) then
begin
inc(j);
setlength(dst1,j);
dst1[j-1]:=sr.name;
i:=findnext(sr);
end;
end; findclose(sr);
end;但是在函数里面不认识这个数组参数dst1,提示未定义!
初学DELPHI,见笑了
myArray:array of string;
pathstr:string;
begin
pathstr='c:\test';
SetDirectName(myArray,pathstr);
showmessage(length(myArray));
end;procedure tform1.SetDirectName(dst1:array of String ; PathName : String);
var
i:integer;
j:integer;
sr:Tsearchrec;
begin
i:=0;
j:=0;
i:=findfirst(pathname+'*.*',faanyfile,sr);
while i=0 do
begin
if (sr.name<>'.') and (sr.name<>'..') and (sr.Attr>=16) and (sr.attr<=17) then
begin
inc(j);
setlength(dst1,j);
dst1[j-1]:=sr.name;
i:=findnext(sr);
end;
end; findclose(sr);
end;但是在函数里面不认识这个数组参数dst1,提示未定义!
初学DELPHI,见笑了
错误提示: incompatible types不知道什么原因?
如果你设的 myArray 是个全局变量,那么他在函数中一定可以被附值,如果是不想用全局变量,那么用一个函数,返回值就是这个附过值的字符串数组,就行了。
type
myArray=array of string; procedure tform1.SetDirectName(dst1:myArray; PathName : String); \
begin
//
//
end;
TMyArray = array of string;procedure tform1.SetDirectName(dst1:pointer; PathName : String);dst1是pointer类型var
myArray:TMyArray;
pathstr:string;
begin
pathstr='c:\test';
SetDirectName(@myArray,pathstr);
showmessage(length(myArray));
end;procedure tform1.SetDirectName(dst1:pointer; PathName : String);
var
i:integer;
j:integer;
sr:Tsearchrec;
begin
i:=0;
j:=0;
i:=findfirst(pathname+'*.*',faanyfile,sr);
while i=0 do
begin
if (sr.name<>'.') and (sr.name<>'..') and (sr.Attr>=16) and (sr.attr<=17) then
begin
inc(j);
setlength(TMyArray(dst1^),j);
TMyArray(dst1^)[j-1]:=sr.name;
i:=findnext(sr);
end;
end; findclose(sr);
end;