Jump to content
skyzoframe[hun]

FMX Error handling. Save out in log file, every success and failed function or procedure.

Recommended Posts

Hi,
I need examples for error handling strategies. Does anyone have any advice?

(Log every success and failed procedure or function.)

Share this post


Link to post

Maybe create a TMemo and save here every log information. And before the program closed, save it out to file.

 

  {$IFDEF MSWINDOWS}



procedure Form1.Log(uiMessage: String);
var
  TimeStamp : TDateTime;
begin
  TimeStamp := Now;
  Memo1.lines.add('--'+DateTimeToStr(TimeStamp)+sLineBreak
                 +uiMessage);
end;

procedure Form1.FormDestroy(Sender: TObject);
var
  BOM: WideChar;
  FS: TFileStream;
  WS: WideString;
  I: Integer;
begin
  FS := TFileStream.Create('.\ini\Log.txt', fmCreate);
  try
    BOM := WideChar($FEFF);
    FS.WriteBuffer(BOM, SizeOf(BOM));
    For I := 0 to  Memo1.Lines.Count-1 do
    begin
      WS := WideString( Memo1.Lines[I] + sLineBreak);
      FS.WriteBuffer(PWideChar(WS)^, Length(WS) * SizeOf(WideChar));
    end;
  finally
    FS.DisposeOf;
  end;
end;

  {$ENDIF}

How to do it on Android?

Edited by skyzoframe[hun]

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×