TListView组件显示文件夹中的文件

procedure GetDirectories(list: TlistView; Directory: string; Item: Tlistitem; IncludeFiles: boolean);
var
SearchRec: TSearchRec;
begin
   list.Items.BeginUpdate;//准备更新
   list.Items.Clear;  //清空list内容
   if Directory[length(Directory)] <> '/' then //判断路径 
         Directory := Directory + '/';  //设置路径
   if FindFirst(Directory + '*.*',faDirectory,SearchRec) = 0 then       begin
             repeat   
             if (SearchRec.Attr and faDirectory = faDirectory) and (SearchRec.Name[1] <> '.') then  
                 begin
                        if (SearchRec.Attr and faDirectory > 0) then                               begin  Item := list.Items.Add;  //增加item
                                        item.Caption:=SearchRec.Name; 
                                        item.ImageIndex:=6;
                              end;
                        GetDirectories(list,Directory + SearchRec.Name,Item,IncludeFiles);
                 end
                               else
               if IncludeFiles then
                            if SearchRec.Name[1] <> '.' then
                                    begin
                                           item:=list.Items.Add;
                                           item.Caption:=SearchRec.Name;
                                           item.ImageIndex:=6;
                                    end;
                      until FindNext(SearchRec) <> 0;
//FindClose(SearchRec);
               end;
      list.Items.EndUpdate;
end;

定义Directory:

procedure makedir(modulname,pathname,dirname,filepath:string);//创建目录(共4级,朋友如果觉得用得上的话,可以自己加参数)
begin
try
    if not directoryexists(frootpath+modulname) then
      createdir(FRootPath+modulname);
    if not DirectoryExists(FRootPath+modulname+'/'+pathname) then
    createdir(FRootPath+modulname+'/'+pathname);
    if not directoryexists(FRootPath+modulname+'/'+pathname+'/'+dirname) then
    createdir(FRootPath+modulname+'/'+pathname+'/'+dirname);
    if filepath<>'' then
    if not directoryexists(FRootPath+modulname+'/'+pathname+'/'+dirname+'/'+filepath) then
    createdir(FRootPath+modulname+'/'+pathname+'/'+dirname+'/'+filepath)
    except
    On E:Exception do begin
    abort;
    end;
    end;
    banjin.N21.Enabled:=true;
   liucheng.MenuItem1.Enabled:=true;
   yanzheng.N21.Enabled:=true;
    banjin.SpeedButton1.Enabled:=true;
    liucheng.SpeedButton1.Enabled:=true;
    yanzheng.SpeedButton1.Enabled:=true;
    banjin.toolbutton1.Enabled:=true;
    liucheng.toolbutton1.Enabled:=true;
    yanzheng.toolbutton1.Enabled:=true;
    if filepath='' then
    filespath:=FRootPath+modulname+'/'+pathname+'/'+dirname+'/'+filepath else
    filespath:=FRootPath+modulname+'/'+pathname+'/'+dirname+'/'+filepath+'/';
    banjin.StatusBar1.Panels[0].Text:='你目前所在的位置:'+filespath;
    liucheng.StatusBar1.Panels[0].Text:='你目前所在的位置:'+filespath;
    yanzheng.StatusBar1.Panels[0].Text:='你目前所在的位置:'+filespath;
end;
如果是二级或一级目录的话,只要加上if filepath<>'' then
类似的判断就可以了,例如:makedir('设计规范','电子件','电路设计规范','');

 

注:在这里写的两个过程没有实现读取windows的图标,如果想实现这一功能的话要自己动手写了 ^_^

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Delphi ,您可以使用 TListView 和 TADOQuery 组件来实现数据库查询结果的显示。下面是一个示例的方法和代码: 1. 在窗体上放置 TListView 和 TADOQuery 组件,并设置相关属性。 2. 在窗体的 OnCreate 事件,创建并打开 ADOQuery 组件,并执行查询语句。 ```delphi procedure TForm1.FormCreate(Sender: TObject); begin ADOQuery1.Connection := ADOConnection1; // 设置 ADOQuery 的连接 ADOQuery1.SQL.Text := 'SELECT * FROM YourTable'; // 设置查询语句 ADOQuery1.Open; // 执行查询 end; ``` 3. 在窗体的 OnShow 事件,将查询结果显示ListView 。 ```delphi procedure TForm1.FormShow(Sender: TObject); var ListItem: TListItem; begin ListView1.Items.Clear; // 清空 ListView 的项 // 遍历查询结果集,将每条记录显示ListView ADOQuery1.First; while not ADOQuery1.Eof do begin ListItem := ListView1.Items.Add; ListItem.Caption := ADOQuery1.FieldByName('Field1').AsString; // 第一列数据 ListItem.SubItems.Add(ADOQuery1.FieldByName('Field2').AsString); // 第二列数据 ADOQuery1.Next; end; end; ``` 在这个例子,我们使用 TListView 的 Items 属性来添加每个查询结果的行,并使用 Caption 和 SubItems 属性来设置每列的数据。可以根据需要添加更多的列和数据。 请注意,上述示例假设您已经在窗体上放置了 TListView(名为 ListView1)、TADOQuery(名为 ADOQuery1)和 TADOConnection(名为 ADOConnection1)组件,并已正确配置 ADOConnection 连接到您的数据库。 希望以上代码对您有所帮助。如果您有任何进一步的问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值