我想浏览SD卡,选择目录和文件,并加载txt文件到我的由Delphi XE5创建的安卓应用程序。
有没有标准的组件或方法来实现这一点?就像OpedFileDialog一样?
发布于 2013-11-08 00:26:24
在安卓系统上,TOpenFileDialog没有类似的功能。它不是操作系统的一部分,并且在面向Android的时候不能从组件面板中获得。
您可以通过在设计器中查看表单,然后检查组件面板中的Dialogs选项卡来查看这一点;所有组件都被禁用,这意味着它们对目标平台不可用。将鼠标悬停在其中任何一个上都表明它们可以用于Win32、Win64和OS,但不能用于iOS或安卓系统。
您始终可以基于TForm (或者更好的是,TPopup,它更适合于移动设备的典型应用程序流),使用IOUtils.TPath中提供的用于检索目录和文件名的功能来构建您自己的and。一旦您有了文件名,加载它的功能就很简单,并且可以通过几种方式使用-以下是几种方法:
同样来自IOUtils)
TStringList.LoadFromFile
TFileStream.LoadFromFile
TMemo.Lines.LoadFromFile,
TFile.ReadAllLines加载它发布于 2013-11-08 00:07:09
通过TStringList.loadFromFile(file);使用TStringList
procedure TForm1.Button1Click(Sender: TObject);
var
TextFile : TStringList;
FileName : string;
begin
try
textFile := TStringList.Create;
try
{$IFDEF ANDROID}//if the operative system is Android
FileName := Format('%smyFile.txt',[GetHomePath]);
{$ENDIF ANDROID}
{$IFDEF WIN32}
FileName := Format('%smyFile.txt',[ExtractFilePath(ParamStr(0))]);
{$ENDIF WIN32}
if FileExists(FileName) then begin
textFile.LoadFromFile(FileName); //load the file in TStringList
showmessage(textfile.Text);//there is the text
end
else begin showMessage('File not exists, Create New File');
TextFile.Text := 'There is a new File (Here the contents)';
TextFile.SaveToFile(FileName);//create a new file from a TStringList
end;
finally
textFile.Free;
end;
except
on E : Exception do ShowMessage('ClassError: '+e.ClassName+#13#13+'Message: '+e.Message);
end;
end;https://stackoverflow.com/questions/19832244
复制相似问题