0
votes

I have a Delphi Firemonkey application implementing a TCP server. The server is not opening the port as expected. I can see the form open but netstat reveals that the port is not opened. I am now attempting to debug this issue by trying to put log messages.

The trouble is I have never used Firemonkey before. I am not sure where I can expect to see the log messages.

I have declared a logging service.

LoggingService: IFMXLoggingService;

And then I initialize it

LoggingService := FMX.Platform.TPlatformServices.Current.GetPlatformService(IFMXLoggingService) as IFMXLoggingService;

And then I call this inside the function Tserver.Execute to make sure that it is executed.

if Assigned(LoggingService) then
  LoggingService.Log('TserverExecute !',[]);

I am not sure where to expect the output. I have checked various debug terminals, can't seem to find the output string anywhere. It would be great if someone could point out what I am doing wrong?

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Platform,
  IdCustomTCPServer, IdTCPServer, IdBaseComponent, IdComponent, IdUDPBase, IdContext,
  IdSocketHandle, IdUDPServer, FMX.Controls.Presentation, FMX.StdCtrls;

type
  TForm1 = class(TForm)
    TCPServer: TIdTCPServer;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TserverExecute(AContext: TIdContext);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  LoggingService: IFMXLoggingService;

implementation

{$R *.fmx}

procedure TForm1.FormCreate(Sender: TObject);
var
  Binding : TIdSocketHandle;
begin
  LoggingService := FMX.Platform.TPlatformServices.Current.GetPlatformService(IFMXLoggingService) as IFMXLoggingService;
  TCPServer.DefaultPort := 16000;
  TCPServer.Bindings.Clear;
  Binding := TCPServer.Bindings.Add;
  Binding.IP := '0.0.0.0';
  Binding.Port := 16000;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
 TCPServer.Active := True;
end;

procedure TForm1.TserverExecute(AContext: TIdContext);
var
  C : String;
begin
  C := AContext.Connection.Socket.ReadLn();
  if Assigned(LoggingService) then
    LoggingService.Log('TserverExecute !',[]);
 if C = 'TESTSTRING' then
 begin
   AContext.Connection.Socket.Writeln('SENT');
 end;
end;

end.
1
Why are you posting this as a new question? You deleted your previous question on this same topic, instead of addressing the comments posted on it. You should have answered what was asked on it so it could be re-opened. - Remy Lebeau
@RemyLebeau - I have put in the debug code.I didn't debug code before. Now I think my immediate concern is how to be able to debug using printf's so that I can understand it better and make some progress. - liv2hak
That is still no excuse for deleting the previous question. Just because it was put on hold does not make it invalid. You were asked to provide more information about it, and you did not do that. That question was about the port issue. This question is about logging instead. Two separate questions, not related to each other, even if they are referring to the same code. - Remy Lebeau

1 Answers

3
votes

I am not sure where to expect the output.

The documentation for IFMXLoggingService.Log() says:

Displays a message in the Event Log.

The Event Log is a window inside the IDE itself (View > Debug Windows > Event Log). It displays log messages generated by an app during a debugging session. So, you need to run your Firemonkey app inside the debugger in order to see the log messages from IFMXLoggingService.