FireMonkey 中是否有用于显示文件系统/文件树的组件?

发布于 2024-12-16 10:24:43 字数 148 浏览 1 评论 0原文

在 FireMonkey 框架中找不到任何文件树组件(当然是跨平台的)。任何人都知道或知道这样的组件吗?对我来说听起来像是一个基本的事情。

我正在寻找一个简单的“类似资源管理器”的树视图,如果它真的很漂亮,那并不重要,因为我可以重新设计它或继承和更改它。想法?...

Couldn't find any file-tree component (cross-platform, of course) in the FireMonkey framework. Anyone has any idea or knows such a component? Sounds like a basic thing to me.

I'm looking for a simple "explorer-like" tree view, not really important if it's really pretty as I can probably restyle it or inherit and change. Ideas?...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2024-12-23 10:24:43

没有没有组件(开箱即用),但您可以使用适用于所有平台的单元System.IOUtils快速实现它。

例如,给您一个想法:

uses
  System.IOUtils, FMX.TreeView, ...

type
  TForm2 = class(TForm)
    tvPath: TTreeView;
    procedure FormCreate(Sender: TObject);
  private
...

procedure TForm2.FormCreate(Sender: TObject);
var
  sRoot    : string;
  sdaDrives: TStringDynArray;
  sDrive   : string;
  tviDrive : TTreeViewItem;
  osv      : TOSVersion;
begin
  if TOSVersion.Platform = pfMacOS then
  begin
    // Root's folders
    sRoot     := '/';
    sdaDrives := TDirectory.GetDirectories(sRoot);
    for sDrive in sdaDrives do
    begin
      tviDrive      := TTreeViewItem.Create(Self);
      tviDrive.Text := sDrive;
      tvPath.AddObject(tviDrive);
    end;
    sdaDrives := TDirectory.GetFiles(sRoot);
  end
  else
  begin
    // Root's folders
    sRoot     := TDirectory.GetDirectoryRoot(ParamStr(0)); // you probably want to use TDirectory.GetLogicalDrives before this one...
    sdaDrives := TDirectory.GetDirectories(sRoot);
    for sDrive in sdaDrives do
    begin
      tviDrive      := TTreeViewItem.Create(Self);
      tviDrive.Text := sDrive;
      tvPath.AddObject(tviDrive);
    end;
    sdaDrives := TDirectory.GetFiles(sRoot);
  end;
  // files
  for sDrive in sdaDrives do
  begin
    tviDrive            := TTreeViewItem.Create(Self);
    tviDrive.Text       := ExtractFileName(sDrive);
    tviDrive.Font.Style := [TFontStyle.fsItalic];
    tvPath.AddObject(tviDrive);
  end;
end;

这只是一个概念证明,因为它可以在两个平台上运行......当然,还有一些工作要做......
我已经使用 System.SysUtils.TOSVersion 向您展示了另一条记录,它可能也很有用......

There's no component (out of the box) but you can quickly implement it using the unit System.IOUtils which is working on all platforms.

For instance, to give you an idea:

uses
  System.IOUtils, FMX.TreeView, ...

type
  TForm2 = class(TForm)
    tvPath: TTreeView;
    procedure FormCreate(Sender: TObject);
  private
...

procedure TForm2.FormCreate(Sender: TObject);
var
  sRoot    : string;
  sdaDrives: TStringDynArray;
  sDrive   : string;
  tviDrive : TTreeViewItem;
  osv      : TOSVersion;
begin
  if TOSVersion.Platform = pfMacOS then
  begin
    // Root's folders
    sRoot     := '/';
    sdaDrives := TDirectory.GetDirectories(sRoot);
    for sDrive in sdaDrives do
    begin
      tviDrive      := TTreeViewItem.Create(Self);
      tviDrive.Text := sDrive;
      tvPath.AddObject(tviDrive);
    end;
    sdaDrives := TDirectory.GetFiles(sRoot);
  end
  else
  begin
    // Root's folders
    sRoot     := TDirectory.GetDirectoryRoot(ParamStr(0)); // you probably want to use TDirectory.GetLogicalDrives before this one...
    sdaDrives := TDirectory.GetDirectories(sRoot);
    for sDrive in sdaDrives do
    begin
      tviDrive      := TTreeViewItem.Create(Self);
      tviDrive.Text := sDrive;
      tvPath.AddObject(tviDrive);
    end;
    sdaDrives := TDirectory.GetFiles(sRoot);
  end;
  // files
  for sDrive in sdaDrives do
  begin
    tviDrive            := TTreeViewItem.Create(Self);
    tviDrive.Text       := ExtractFileName(sDrive);
    tviDrive.Font.Style := [TFontStyle.fsItalic];
    tvPath.AddObject(tviDrive);
  end;
end;

This is just a proof of concept, as it works on both platform.. of course, there's still some work to do...
I have used System.SysUtils.TOSVersion to show you another record which can maybe be also useful...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文