I want to create/read a generic file by FireMonkey C++ in iOS. I've a problem (exception) in file action.
my sample code is :
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.fmx"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::CreateFileClick(TObject *Sender)
{
MessageDlg(L"Start ...", TMsgDlgType::mtError, TMsgDlgButtons() << TMsgDlgBtn::mbYes, 0);
TFileStream *writeFS = NULL;
try
{
writeFS = new TFileStream(L"sample.txt", fmCreate | fmShareDenyNone);
writeFS->WriteComponent(Edit1);
MessageDlg(L"create finished ...", TMsgDlgType::mtInformation, TMsgDlgButtons() << TMsgDlgBtn::mbYes, 0);
}
catch(...)
{
if (writeFS != NULL)
delete writeFS;
MessageDlg(L"create failed!", TMsgDlgType::mtError, TMsgDlgButtons() << TMsgDlgBtn::mbYes, 0);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ReadFileClick(TObject *Sender)
{
Edit2->Text = L"";
TFileStream *readFS = NULL;
try
{
readFS = new TFileStream(L"sample.txt", fmOpenRead);
readFS->ReadComponent(Edit2);
MessageDlg(L"read finished ...\n" + Edit2->Text, TMsgDlgType::mtInformation, TMsgDlgButtons() << TMsgDlgBtn::mbYes, 0);
}
catch(...)
{
if (readFS != NULL)
delete readFS;
MessageDlg(L"read failed!", TMsgDlgType::mtError, TMsgDlgButtons() << TMsgDlgBtn::mbYes, 0);
}
}
//---------------------------------------------------------------------------
but in run-time, iPhone device raise an exception below:
Project Project1 raised exception class EFCreateError with message 'Cannot create file "/sample.txt". Not a directory'.
could you help me.
regards
Ghader