用FindFirst先,把关于文件的那个结构定义成全局变量,在keydown里findnext,esc退出循环。做两个不同的keydown事件,一个是findnext,一个是正常的处理事件,根据不同情况赋不同事件

解决方案 »

  1.   

    搜索文件夹中的,wk_knife,我还是不是很懂,能写部分代码出来吗?我还可以再加分。
      

  2.   

    用 wk_knife(隐生宙) 的方法不能倒退着看,
    还是用stringlist比较好
      

  3.   

    我的办法是不大好,不过可以存放每个看过的文件在stringlist,这样就会好一些。
      

  4.   

    觉得给20分太少了,这样吧,wk_knife(隐生宙),你把代码写出来,我给你50分。我的递归不是很熟
      

  5.   

    刚收到《程序员大本营2001》的光盘,发现一个现成的例子,贴上来。unit FileSearchUnit;(* TFileSearch by Nicola {MSX} Lugato [email protected]
     http://msx.rules.it A simple component that incapsulate
     FindFirst FindNext and FindClose procedures Usage: You can call OpenSearch to start a new search with specified
     arguments. Once opened call NextMatch to get results until
     it returns false. Than call CloseSearch. Alternatively you can call PerformeAction. With
     PerformeAction you specify the action to performe on each
     file that respond to your search in metod OnPerformeAction.
     In this case you can also use the IncludeSubdirectory to
     perform the action even on subdirs. if you like this component and use it, please
     tell me: [email protected]
    *)interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;type TOnActionEvent = procedure (Sender: TObject; Path:String; FileName:String) of object;
    type
      TFileSearch = class(TComponent)
      private
       searching:boolean;
       action:TOnActionEvent;
       first:boolean;
       ffilter,fpath:string;
       fattr:integer;
       sr:TSearchRec;
        { Private declarations }
      protected
        { Protected declarations }
      public
       constructor Create(AOwner: TComponent); override;
       procedure OpenSearch(path:string;filter:string; attributes:integer);
       procedure CloseSearch;
       procedure PerformAction(path:string;filter:string;  attributes:integer; IncludeSubdirectory:boolean);
       function NextMatch(var SearchRec:TSearchRec):boolean;  published   property OnPerformeAction: TOnActionEvent read Action write Action;
      end;procedure Register;implementationprocedure AdjustSlash(var s:string);
    begin
    if s[length(s)]<>'\' then s:=s+'\';
    end;procedure TFileSearch.PerformAction(path:string;filter:string; attributes:integer; includesubdirectory:boolean);
    var x:TSearchRec;
        s:TstringList;
        i:integeR;
        fs:TFileSearch;
    begin
    OpenSearch(path, filter, attributes);
    while NextMatch(x) do
     if Assigned(action) then
      begin
       // Use this to reset file attributes
       //SetFileAttributes(pchar(fpath+x.Name),FILE_ATTRIBUTE_NORMAL);
       action(self, fpath, x.Name);
      end;
    CloseSearch;if IncludeSubdirectory then
     begin
      s:=TStringList.create;
      OpenSearch(path, '*.*', faDirectory);
      while NextMatch(x) do
       if ((x.Attr and fadirectory)<>0) and (x.Name<>'.') and (x.Name<>'..') then
        s.Add(x.Name);
      CloseSearch;
      AdjustSlash(path);
      fs:=TFileSearch.Create(self);
      fs.OnPerformeAction:=action;
      for i:=0 to s.Count-1 do
       fs.PerformAction(path+s[i],filter,attributes,true);
      fs.free;
     end;
    end;constructor TFileSearch.Create(AOwner: TComponent);
    begin
    inherited Create(AOwner);
    searching:=false;
    first:=false;
    end;function TFileSearch.NextMatch(var SearchRec:TSearchRec):boolean;
    begin
    if first then
     begin
      result:=(FindFirst(fPAth+ffilter,fAttr,sr)=0);
      first:=false;
     end
    else
     result:=(FindNext(sr)=0);SearchRec:=sr;
    end;procedure TFileSearch.OpenSearch(path:string;filter:string; attributes:integer);
    begin
    if searching then
     raise Exception.Create('TFileSearch: Already searching. Use CloseSearch to terminate previous search.');
    adjustslash(path);
    ffilter:=filter;
    fpath:=path;
    fattr:=attributes;
    searching:=true;
    first:=true;
    end;procedure TFileSearch.CloseSearch;
    begin
    if not searching then
     raise Exception.Create('TFileSearch: Not searching. Use CloseSearch only after OpenSearch.');
    FindClose(sr);
    searching:=false;
    first:=true;
    end;procedure Register;
    begin
      RegisterComponents('MSX', [TFileSearch]);
    end;end.
      

  6.   

    这是一个控件,先安装。然后就可以从组件面板选取它。
    存为名称和Unit说明一样的名称,然后再‘Component\Install Component'
    选取该文件,OK后,出现一个对话框,选Inatall.