如何使用Firemonkey在Android内存中显示可用文件

  发布于 2023-02-13 15:17

在Delphi for Windows中,有一个TOpenDialog和它的命令FindFirst.在Firemonky/Android中,没有TOpenDialog , but according to many forumsFindFirst`应该存在.然而,有更多的人有问题,但没有解决方案:

在Windows中,以下功能正常:

var iResult,n:integer;
Filenaam,s:string;
sr: TSearchRec;

begin

with form1 do
begin
    L_toonactie.Text:='start file list';
    M_filelist.lines.Clear;
    Filenaam:=
          System.IOUtils.tpath.GetDocumentsPath+'\assets\internal\'+'*.*';          
    iResult:=FindFirst(Filenaam,faAnyFile,sr); 
    str(iresult,s);L_toonactie.Text:='started '+s;
    n:=0;
    while (iResult=0) do
    begin
        inc(n);
        L_toonactie.Text:='busy file list';
        s:=s+sr.Name+sLineBreak;
        M_filelist.lines.add(sr.name);
        iResult:=FindNext(sr);
    end;
  FindClose(sr);
 // str(n,s);if n=0 then L_toonactie.Text:='nothing found' 
else L_toonactie.Text:='ready file list ('+s+'found)'

结束;}

iResult 永远都有 -1

另一个解决方案是:

procedure toon_files2(pathSTRING:string);  
var
   {$IFDEF FPC}
   patharray : NSArray;
   filename,path,ext,subdir:NSString ;
   fileManager: NSFileManager ;
   direnum:NSEnumerator;//NSDirectoryEnumerator ;//NSDirectoryEnumerator;
   //direnum:NSDirectoryEnumerator ;//NSDirectoryEnumerator;
   i,n:integer;
   error:NSError;
   {$ENDIF}
   k:integer;
begin
form1.L_toonactie.Text:='start file list';

{$IFDEF FPC}
path:= NSSTR(PChar(pathSTRING)); // =NSHomeDirectory();//
fileManager:= NSFileManager.defaultManager;
patharray:= fileManager.contentsOfDirectoryAtPath_error(path,@error);
n:=0;
k:=0;
direnum:= patharray.objectEnumerator ;
repeat
    inc(k);
    filename:=direnum.nextObject;
    if string(fileName.UTF8STRING)<>'' then
    begin
        ext:= filename.pathExtension;
        if UpperCase(string(ext.UTF8STRING))='KPF' then
        begin
            form1.L_toonactie.Text:='found a file';
            SetLength(pngLIST,n+1);
            pngLIST[n]:=string(Path.UTF8STRING)+string(filename.UTF8STRING);
            form1.memo1.Lines.Add(pngLIST[n]) ;
            inc(n);
        end;
    end;
until string(fileName.UTF8STRING)='';
{$ENDIF}

if k=0 then form1.L_toonactie.Text:='nothing found' 
else form1.L_toonactie.Text:='ready file list';
end;

但也不起作用.

1 个回答
  • 在提供的功能IOUtils是你所需要的.此代码(在我的Nexus 7上测试)填充TMemo文件夹中的文件(如果有的话):

    uses
      IOUtils;
    
    procedure THeaderFooterForm.SpeedButton1Click(Sender: TObject);
    var
      DirList: TStringDynArray;
      DirPath: string;
      s: string;
    begin
      DirPath := TPath.Combine(TPath.GetDocumentsPath, 'assets');
      DirPath := TPath.Combine(DirPath, 'internal');
    
      // Display where we're looking for the files
      Memo1.Lines.Add('Searching ' + DirPath);
    
      if TDirectory.Exists(DirPath, True) then
      begin
        // Get all files. Non-Windows systems don't typically care about
        // extensions, so we just use a single '*' as a mask.
        DirList := TDirectory.GetFiles(DirPath, '*');
    
        // If none found, show that in memo
        if Length(DirList) = 0 then
          Memo1.Lines.Add('No files found in ' + DirPath)
        else // Files found. List them.
        begin 
          for s in DirList do
            Memo1.Lines.Add(s);
        end;
      end
      else
        Memo1.Lines.Add('Directory ' + DirPath + ' does not exist.');
    end;
    

    2023-02-13 15:19 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有