Open and read a file in firemonkey

  

What is wrong in this code ? I don’t understend, if I remove the “Try” my app dont open, and if don’t remove always appear “need login” …

procedure TF_login.FormActivate(Sender: TObject);
var
Result: Integer;
TextFile: TStringList;
VarArquivo: string;
text: string;
dataI, dataF : string;
begin
TextFile := TStringList.Create;
VarArquivo := System.IOUtils.TPath.GetDocumentsPath + PathDelim + ‘Limit.txt’;
try
TextFile.LoadFromFile(VarArquivo);

text := TextFile.Text;
// ShowMessage(TextFile.Text); // there is the text
// ShowMessage(text); // there is the text

dataI := FormatDateTime(‘dd/mm/yyyy’, Now);
dataF := FormatDateTime(‘dd/mm/yyyy’, StrToDate(text));

Result := CompareDate(StrToDate(dataI), StrToDate(dataF));
ShowMessage(dataF +’ data f’);
ShowMessage(dataI +’ data I’);
if ( Result = LessThanValue ) then
begin
ShowMessage(‘data F low’);
end
else
begin
ShowMessage(‘data F high’);
F_inicio.Show;
end;

FreeAndNil(TextFile);
except on E:
Exception do ShowMessage(‘An error happened!’ + sLineBreak + ‘[‘ +
E.ClassName + ‘] ‘ + E.Message);
end;
end;

The error : [EConvertError] ’09/11/2019’ is not a valid date

to create the file, i do:

procedure TF_login.btn_entrarClick(Sender: TObject);
var
data : tdatetime;
Resposta, data_s: string;
begin
PathFile := System.IOUtils.TPath.GetDocumentsPath;
NameFile := ‘Limit.txt’;
data := Now; //data actual
data := IncMonth(data, 2);
data_s := FormatDateTime(‘dd/mm/yyyy’, data);
TFile.WriteAllText(TPath.Combine(PathFile, NameFile), data_s );
F_inicio.Show;
end;

The file exists, because the first (and second) ShowMessage (what is commented) show me the “09/11/19” but the third and fourth not appear to me…

OBS: Delphi 10.3 (RIO), Plataform: Android

Comments are closed.