Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
Delphi

Reading and writing files from an iOS FireMonkey application

Author: dragonhome

Here’s an example of how you can read and write files in your iOS FireMonkey application.

Enjoy!

{$IFDEF FPC}
var
content : NSString;
{$ENDIF}

{$IFDEF FPC}
function MyFileName : NSString;
var
paths : NSArray;
fileName : NSString;
begin
paths := NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, True);
fileName := paths.objectAtIndex(0);
fileName.stringByAppendingString(NSSTR(PChar(‘/myfile.txt’)));
Result := fileName;
end;
{$ENDIF}

procedure TForm1.Button1Click(Sender: TObject);
begin
// Write to file
{$IFDEF FPC}
Label2.Text := ‘Wrote to: ‘+String(MyFileName.UTF8String);
content := NSSTR(PChar(String(Memo1.Text)));
content.writeToFile_atomically_encoding_error(MyFileName,False,NSStringEncodingConversionAllowLossy,nil);
content.release;
{$ENDIF}
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
// Read from file
{$IFDEF FPC}
Label2.Text := ‘Read from ‘+String(MyFileName.UTF8String);
content.InitWithContentsOfFile_usedEncoding_error(MyFileName,nil,nil);
Memo1.Text := String(content.UTF8String);
content.release;
{$ENDIF}
end;

Interested in learning how to read and write files from an iOS FireMonkey application? You may use the App Builder Software and make the most of it. 
Try the free tool here.

Coding Boot Camp

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

Related posts
C++DelphiRAD StudioWindows

6 Best UI Toolkits For Windows

C++DelphiRAD Studio

The Next Big Thing in Native Windows Development

C++Code

This Week's New C++ Post Picks From LearnCPlusPlus.org

C++CodeIDERAD Studio

LearnCPlusPlus.org :: Object-Oriented Programming, Structs, Classes, Objects, And More

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES