gpt4 book ai didi

android - 如何使用 Firemonkey 显示 Android 内存中的可用文件

转载 作者:太空宇宙 更新时间:2023-11-03 12:55:55 25 4
gpt4 key购买 nike

在 Delphi for Windows 中,有 TOpenDialog 和诸如 FindFirst 之类的命令。在 Firemonky/Android 中没有 TOpenDialog,但根据许多论坛FindFirst` 应该存在。但是有更多人遇到问题,但没有解决方案:

在 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;

但也不行。

最佳答案

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;

关于android - 如何使用 Firemonkey 显示 Android 内存中的可用文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20318875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com