Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: How to read and save a text file in FireMonkey for Android



Permlink Replies: 6 - Last Post: Feb 20, 2017 3:56 PM Last Post By: Antonio Estevez
Xavier Yang

Posts: 17
Registered: 6/28/02
How to read and save a text file in FireMonkey for Android
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2016 10:13 AM
Dear all,
I have tried to transfer a small application C++Builder into FireMonkey under XE10 Seattle.
I realize that many VCL components or functions such as OpenDialog, SaveDislog, Open, etc are not supported by Android deployment.
It is sure there are equivalent instructions, but I haven't got yet. Even in Sample, I didn't get a simple example.
What I want is to read and save a text file in Android Mobile Platform.
Tank you very much if you have a short sample.
Cheers
Xavier.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to read and save a text file in FireMonkey for Android
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2016 11:27 AM   in response to: Xavier Yang in response to: Xavier Yang
Xavier wrote:

I realize that many VCL components or functions such as OpenDialog,
SaveDislog, Open, etc are not supported by Android deployment.

Those are just components for letting the user select filenames. And no,
Android does not have native dialogs to provide that, you have to provide
your own UIs for it. But they do not actually create/open files, you have
to manage that in your own code.

What I want is to read and save a text file in Android Mobile Platform.

What is the problem exactly? That you don't know how to ask the user for
a filename? Or that you don't know how to actually create/open/read/write
the files themselves one you have a filename? Have you looked at the TStringList,
TFileStream, or TStreamReader/TStreamWriter classes yet?

--
Remy Lebeau (TeamB)
Xavier Yang

Posts: 17
Registered: 6/28/02
Re: How to read and save a text file in FireMonkey for Android
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2016 8:29 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Xavier wrote:

I realize that many VCL components or functions such as OpenDialog,
SaveDislog, Open, etc are not supported by Android deployment.

Those are just components for letting the user select filenames. And no,
Android does not have native dialogs to provide that, you have to provide
your own UIs for it. But they do not actually create/open files, you have
to manage that in your own code.

What I want is to read and save a text file in Android Mobile Platform.

What is the problem exactly? That you don't know how to ask the user for
a filename? Or that you don't know how to actually create/open/read/write
the files themselves one you have a filename? Have you looked at the TStringList,
TFileStream, or TStreamReader/TStreamWriter classes yet?

--
Remy Lebeau (TeamB)

Infact, I want to do the equivalent functions of VCL such as OpenDialog to get file name, Open for reading an existing file, then SaveDialog for saving traited file to the local SD. Naturally, I need to create/open files. The problem exact is to transfer the same function already created in VCL into mobile Andoid application. For example, read an existing ASCII file, carry out some computation and display it on smart phone by both TChat and TStringGrid.
OK for using TChat and TStringGrid, but presently, I don't know how to open a file.
I haven't looked at the TStringList, TFileStream, or TStreamReader/TStreamWriter classes yet. I'll try to understand and use these components.

Cheers
Xavier
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: How to read and save a text file in FireMonkey for Android
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 4, 2016 10:02 PM   in response to: Xavier Yang in response to: Xavier Yang
Xavier wrote:

Infact, I want to do the equivalent functions of VCL such as
OpenDialog to get file name

There is no direct equivilent on Android. You will have to create your own
UI for it. There are plenty of solutions posted online for this.

then SaveDialog

There is no direct equivilent on Android. You will have to create your own
UI for it. There are plenty of solutions posted online for this.

Open for reading an existing file ... saving traited file to the local SD

The RTL has plenty of functions and classes available for working with files,
and they work on all platforms.

The problem exact is to transfer the same function already created in
VCL into mobile Andoid application.

VCL is not FMX. You have to stop thinking in desktop terms when writing
for mobile. Mobile does things a bit differently.

I haven't looked at the TStringList, TFileStream, or
TStreamReader/TStreamWriter classes yet. I'll try to understand
and use these components.

They are not components, just classes. Also look at the RTL's FileCreate()/FileOpen(),
FileRead(), and FileWrite() functions.

Or, if you are really adventurous, you could just ditch the RTL's classes/functions
and use Androids native File, FileReader, and FileWriter class directly instead.

--
Remy Lebeau (TeamB)
Jorge Uriarte

Posts: 41
Registered: 11/28/14
Re: How to read and save a text file in FireMonkey for Android
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2017 2:49 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:
Xavier wrote:

Infact, I want to do the equivalent functions of VCL such as
OpenDialog to get file name

There is no direct equivilent on Android. You will have to create your own
UI for it. There are plenty of solutions posted online for this.

then SaveDialog

There is no direct equivilent on Android. You will have to create your own
UI for it. There are plenty of solutions posted online for this.

Open for reading an existing file ... saving traited file to the local SD

The RTL has plenty of functions and classes available for working with files,
and they work on all platforms.

The problem exact is to transfer the same function already created in
VCL into mobile Andoid application.

VCL is not FMX. You have to stop thinking in desktop terms when writing
for mobile. Mobile does things a bit differently.

I haven't looked at the TStringList, TFileStream, or
TStreamReader/TStreamWriter classes yet. I'll try to understand
and use these components.

They are not components, just classes. Also look at the RTL's FileCreate()/FileOpen(),
FileRead(), and FileWrite() functions.

Or, if you are really adventurous, you could just ditch the RTL's classes/functions
and use Androids native File, FileReader, and FileWriter class directly instead.

--
Remy Lebeau (TeamB)

Not everyone subscribes to RTL. Can someone share a simple sample to save a text file from "Memo" and load a text file to memo?
Thanks

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: How to read and save a text file in FireMonkey for Android
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 20, 2017 3:56 PM   in response to: Jorge Uriarte in response to: Jorge Uriarte
El 20/02/2017 a las 23:49, Jorge Uriarte escribió:

Not everyone subscribes to RTL. Can someone share a simple sample to save a text file from "Memo" and load a text file to memo?
Thanks

#include <System.IOUtils.hpp>
 
void __fastcall TForm2::ButtonSaveTextClick(TObject *Sender)
{
    String FileName= Ioutils::TPath::Combine(
                     Ioutils::TPath::GetDocumentsPath(), _D("Test.txt"));
 
    Memo1->Lines->SaveToFile(FileName);
}
 
void __fastcall TForm2::ButtonLoadTextClick(TObject *Sender)
{
    String FileName= Ioutils::TPath::Combine(
                     Ioutils::TPath::GetDocumentsPath(), _D("Test.txt"));
 
    Memo1->Lines->LoadFromFile(FileName);
}
Xavier Yang

Posts: 17
Registered: 6/28/02
Re: How to read and save a text file in FireMonkey for Android
Click to report abuse...   Click to reply to this thread Reply
  Posted: Feb 5, 2016 8:44 AM   in response to: Xavier Yang in response to: Xavier Yang
Thank you Remy for your detail explications.
I'll try to understand and use RTL functions.
Cheers
Xavier

Xavier Yang wrote:
Remy Lebeau (TeamB) wrote:
Xavier wrote:

I realize that many VCL components or functions such as OpenDialog,
SaveDislog, Open, etc are not supported by Android deployment.

Those are just components for letting the user select filenames. And no,
Android does not have native dialogs to provide that, you have to provide
your own UIs for it. But they do not actually create/open files, you have
to manage that in your own code.

What I want is to read and save a text file in Android Mobile Platform.

What is the problem exactly? That you don't know how to ask the user for
a filename? Or that you don't know how to actually create/open/read/write
the files themselves one you have a filename? Have you looked at the TStringList,
TFileStream, or TStreamReader/TStreamWriter classes yet?

--
Remy Lebeau (TeamB)

Infact, I want to do the equivalent functions of VCL such as OpenDialog to get file name, Open for reading an existing file, then SaveDialog for saving traited file to the local SD. Naturally, I need to create/open files. The problem exact is to transfer the same function already created in VCL into mobile Andoid application. For example, read an existing ASCII file, carry out some computation and display it on smart phone by both TChat and TStringGrid.
OK for using TChat and TStringGrid, but presently, I don't know how to open a file.
I haven't looked at the TStringList, TFileStream, or TStreamReader/TStreamWriter classes yet. I'll try to understand and use these components.

Cheers
Xavier
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02