Recent

Author Topic: Raspbery Pi, TCustomApplication class  (Read 2645 times)

ertank

  • Full Member
  • ***
  • Posts: 240
Raspbery Pi, TCustomApplication class
« 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
« Last Edit: December 26, 2017, 11:54:08 am by ertank »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8075
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Raspbery Pi, TCustomApplication class
« Reply #1 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