我想作个给数组赋值的过程,可以这样调用: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,见笑了

解决方案 »

  1.   

    好像不止这些错误pathstr='c:\test';   // pathstr:='c:\test'; showmessage(length(myArray))  // showmessage(inttostr(length(myarray)));做字符串数组还是用 TStringList 吧
      

  2.   

    to citytramper(阿琪):谢谢,不过上面是书写小错误。这一句:setlength(dst1,j);
    错误提示: incompatible types不知道什么原因?
      

  3.   

    不太清楚你是什么意思。
      如果你设的 myArray 是个全局变量,那么他在函数中一定可以被附值,如果是不想用全局变量,那么用一个函数,返回值就是这个附过值的字符串数组,就行了。
      

  4.   

    我的myArray 是公共变量的呀,为什么在函数体内总提示 incompatible types错误呢?
      

  5.   

    你要把数组作为函数参数,必须先定义一个数组类型。如下:
      type 
        myArray=array of string;  procedure tform1.SetDirectName(dst1:myArray; PathName : String); \
      begin
      //
      //
      end;
      

  6.   

    当数组作为参数的时候,编译器并不认为它是动态数组,所以setlength(dst1,j);报错我建议使用TStringList如果非要用动态数组也可以,要变通一下,传入数组的指针type
      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;