Lazarus

Programming => Operating Systems => Other => Topic started by: ertank on December 26, 2017, 11:28:01 am

Title: Raspbery Pi, TCustomApplication class
Post by: ertank on December 26, 2017, 11:28:01 am
Hello,

I am using Lazarus (trunk, SVN 56813). When I write a code similar to below I see that Terminated property is True and application instantly free itself and exit.

Definition:
Code: [Select]
TMyInterfaceServer = class(TCustomApplication)
  protected
    procedure DoRun; override;
  private
    LogDir: string;
    procedure RunServer();
  public
    constructor Create(TheOwner: TComponent); override;
    destructor Destroy; override;
    procedure WriteHelp; virtual;
  end;
end.

Usage:
Code: [Select]
var
  Application: TMyInterfaceServer;
begin
  Application := TMyInterfaceServer.Create(nil);
  Application.Run();
  Application.RunServer();
  while not Application.Terminated do Sleep(1000);  // execution instantly exit and do not wait here
  Application.Free();
end.

I could not see any FTerminated := False in creation code of TCustomApplication. It seems to be included in Initialize() procedure.

Question is: Is my usage above wrong and I should put it as below?
Code: [Select]
var
  Application: TMyInterfaceServer;
begin
  Application := TMyInterfaceServer.Create(nil);
  Application.Initialize();
  Application.Run();
  Application.RunServer();
  while not Application.Terminated do Sleep(1000);  // execution instantly exit and do not wait here
  Application.Free();
end.

Thanks & regards,
Ertan
Title: Re: Raspbery Pi, TCustomApplication class
Post by: Leledumbo on December 26, 2017, 12:33:16 pm
I could not see any FTerminated := False in creation code of TCustomApplication. It seems to be included in Initialize()
procedure.
Correct, read Initialize documentation: https://www.freepascal.org/docs-html/fcl/custapp/tcustomapplication.initialize.html
Question is: Is my usage above wrong and I should put it as below?
Neither, again read how Run is expected to behave: https://www.freepascal.org/docs-html/fcl/custapp/tcustomapplication.run.html