全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1347
推到 Plurk!
推到 Facebook!

討論一個範例 Listview 顯示檔名並及圖示

尚未結案
zombit
初階會員


發表:63
回覆:39
積分:30
註冊:2004-05-11

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-04-11 21:54:16 IP:61.62.xxx.xxx 未訂閱
http://www.swissdelphicenter.ch/en/showcode.php?id=421 我的程式碼如下, 可是 Button 按下去, 只有出現   ListView1.Columns.Add;   ListView1.Columns.Add; 的效果, Listview 那邊會多兩格.    可是檔案名跟圖標都沒有列出來, 請問有人可以跑出他範例的樣子嗎? 謝謝.    
unit Unit1;    interface    uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, ComCtrls, StdCtrls;    type
  TForm1 = class(TForm)
    ListView1: TListView;
    ImageList1: TImageList;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;    var
  Form1: TForm1;    implementation    {$R *.dfm}    uses
  ShellApi;    procedure LV_InsertFiles(strPath: string; ListView: TListView; ImageList: TImageList);
var
  i: Integer;
  Icon: TIcon;
  SearchRec: TSearchRec;
  ListItem: TListItem;
  FileInfo: SHFILEINFO;
begin
  // Create a temporary TIcon
  Icon := TIcon.Create;
  ListView.Items.BeginUpdate;
  try
    // search for the first file
    i := FindFirst(strPath   '*.*', faAnyFile, SearchRec);
    while i = 0 do
    begin
      with ListView do
      begin
        // On directories and volumes
        if ((SearchRec.Attr and FaDirectory <> FaDirectory) and
          (SearchRec.Attr and FaVolumeId <> FaVolumeID)) then
        begin
          ListItem := ListView.Items.Add;
          //Get The DisplayName
          SHGetFileInfo(PChar(strPath   SearchRec.Name), 0, FileInfo,
            SizeOf(FileInfo), SHGFI_DISPLAYNAME);
          Listitem.Caption := FileInfo.szDisplayName;
          // Get The TypeName
          SHGetFileInfo(PChar(strPath   SearchRec.Name), 0, FileInfo,
            SizeOf(FileInfo), SHGFI_TYPENAME);
          ListItem.SubItems.Add(FileInfo.szTypeName);
          //Get The Icon That Represents The File
          SHGetFileInfo(PChar(strPath   SearchRec.Name), 0, FileInfo,
            SizeOf(FileInfo), SHGFI_ICON or SHGFI_SMALLICON);
          icon.Handle := FileInfo.hIcon;
          ListItem.ImageIndex := ImageList.AddIcon(Icon);
          // Destroy the Icon
          DestroyIcon(FileInfo.hIcon);
        end;
      end;
      i := FindNext(SearchRec);
    end;
  finally
    Icon.Free;
    ListView.Items.EndUpdate;
  end;
end;    procedure TForm1.Button1Click(Sender: TObject);
begin
  // Assign a Imagelist to the ListView
  ListView1.SmallImages := ImageList1;
  // Show Listview in Report Style and add 2 Columns
  ListView1.ViewStyle := vsReport;
  ListView1.Columns.Add;
  ListView1.Columns.Add;
  LV_InsertFiles('c:\tmp', ListView1, ImageList1);
end;    end.    
zombit
初階會員


發表:63
回覆:39
積分:30
註冊:2004-05-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-04-11 22:14:36 IP:61.62.xxx.xxx 未訂閱
對不起,多貼了. 請砍.謝謝
系統時間:2024-06-27 0:08:13
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!