首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

为啥方法中的值会见了呢

2013-01-11 
为什么方法中的值会见了呢?procedure _GetexeName(strName,ASourFile,FileName: string)var sour_path,so

为什么方法中的值会见了呢?
procedure _GetexeName(strName,ASourFile,FileName: string);
var sour_path,sour_file: string;
TmpList:TStringList;
FileRec:TSearchrec;
i: Integer;
begin
  if rightStr(trim(ASourFile), 1) <> '\' then
  sour_path :=trim(ASourFile) + '\'
  else
  sour_path :=trim(ASourFile);
  sour_file:= FileName;

  if not DirectoryExists(sour_path) then  //判断有没有目录
  begin
  exit;
  end;

  TmpList:=TStringList.Create;
  TmpList.Clear;

  if FindFirst(sour_path+'*',faAnyfile,FileRec) = 0 then
  begin
    repeat
      Application.ProcessMessages;

      if ((FileRec.Name = '.') or (FileRec.Name = '..')) then Continue; //判断文件是否为'.','..'。是就结束循环
      if DirectoryExists(sour_path + FileRec.Name) then //判断是否有目录
      begin
           continue;
        //_GetFileList1(AStrings, sour_path+ FileRec.Name + '\', sour_file);
      end
      else
      begin
        if (UpperCase(extractfileext(sour_Path + FileRec.Name)) = UpperCase(FileName)) or (FileName = '.*') then
          TmpList.Add(FileRec.Name);
      end;
    until FindNext(FileRec)<>0;

  SysUtils.FindClose(FileRec);
  end;

  for i := 0 to TmpList.Count -1 do
  begin
  if Pos('jsj', TmpList.Strings[i]) > 0 then
  strName:= TmpList.Strings[i];//方法里面,这里的strName等与'YTjsj.exe'。但是下面调用之后,strName还是空
  end;
  TmpList.Free;
end;

//下面是调用
_GetexeName(strName,'这是路径', '.exe');
strName的值是'';//为什么啊?

这是遍历文件夹下的。exe文件,然后名字中含有‘jsj’的就赋值给strName。但是调用这个方法后,strName是空的。可以我调试的时候strName明明有值的。
这到底是为什么啊?求大牛解答。
[解决办法]
strName是形参,这里是传值的操作,不会改变原来的值,想要改变原来的值加上var
[解决办法]
Out方式也可以。
[解决办法]
变量参数。。

热点排行