関数で得た動的配列を戻り値にするには?


saki  2002-03-24 17:25:36  No: 699  IP: [192.*.*.*]

初めまして、昔vbで作ったものdelphiでを再び作り出したのですが、delphi  
難しいですね
質問なのですが、あるフォルダ内に入ってるファイル名を全て配列で取得
して、そのファイル名が全て入ってる配列を戻したいのですがやり方がよく分
かりません  見にくくなるのですが
var
  strOldName:array of string;
  intValFile:integer;
begin
  intValFIle:=0;
  if 0=FindFirst(strFolderPath+'*.*', faAnyFile, SearchRec) then begin
    repeat
      if (SearchRec.Attr and faDirectory = 0) and
        (SearchRec.Attr and faHidden = 0) then begin

        SetLength(strOldName,intValFile+1);
        strOldName[intValFile]:=SearchRec.Name;
        intValFile:=intValFile+1;

      end;
    until 0<>FindNext(SearchRec);

    FindClose(SearchRec);
  end;

  Result:=strOldName;     ←ここでエラーが出ます
end;

また呼び出し元の宣言は
var
  strOldName:array of string;
  strFolderPath:string;//対象フォルダパス
begin
  strOldName:=MaeShori(strFolderPath);//上の関数呼び出し
end;

みたいな感じでstrOldNameは動的配列宣言してるのですが、配列数がこの時点
では分からないため決めれません  このままでいいのでしょうか?
長文で申し訳ないのですが、お願いします

編集 削除
なんでん念  2002-03-25 04:33:32  No: 700  IP: [192.*.*.*]

なんちゅうか、Delphiに不慣れなあんさんやな〜
関数の書式が分かっとらんチャウか。
関数より変数パラメータがエエがな。

//----------------------------------------------
//最初に array of string型を定義しといて使いなはれ。
type
  TArrayOfString = array of string;

//-------------------------------------------
procedure TForm1.MaeShori(const strFolderPath: string; var strOldName: TArrayOfString);
var
  intValFile: Integer;
  SearchRec : TSearchRec;
begin
  intValFIle := 0;
  if 0 = FindFirst(strFolderPath+'*.*', faAnyFile, SearchRec) then begin
    repeat
      if (SearchRec.Attr and faDirectory = 0) and
          (SearchRec.Attr and faHidden = 0) then begin
        SetLength(strOldName, intValFile + 1);
        strOldName[intValFile] := SearchRec.Name;
        intValFile := intValFile + 1;
      end;
    until 0 <> FindNext(SearchRec);
    FindClose(SearchRec);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  strOldName   : TArrayOfString;
  strFolderPath: string; //対象フォルダパス
  i : Integer;
begin
  strFolderPath := 'C:\Windows\Temp\';
  MaeShori(strFolderPath, strOldName); //上の手続き呼び出し
  with ListBox1 do begin
    Clear;
    for i:=0 to High(strOldName) do begin
      Items.Add(strOldName[i]);
    end;
  end;
end;
//--------------------------------------------

編集 削除
saki  2002-03-25 23:08:13  No: 701  IP: [192.*.*.*]

なんでん念さん、レス有難うございます
あっさりと不慣れさ見抜かれましたね(^;
参照渡し使うということは、関数で戻すのではなく手続きで直接strOldName
を変えてしまった方がいいみたいですね
ところで
var
  strOldName : TArrayOfString;

なんですが、var strOldName:array of string;
にするより何故いいのでしょうか?不慣れついでに教えてもらえませんか?

編集 削除
なんでん念  2002-03-26 06:40:09  No: 702  IP: [192.*.*.*]

>var strOldName:array of string;
>にするより何故いいのでしょうか?

array of stringでやって見んかい?
やれば分かるで〜(^^;;

編集 削除