Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2015-10

Which program type to select for cron usage?

8 messages · 5 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I am finally ready to start creating my FPC/Lazarus control application based on a number of Delphi support units. The application is meant to be started on a Raspberry Pi2 by cron every minute or so and basically check if there is something to do and if not just exit. But if there is stuff to do it will create the needed control objects and start communicating with a data collection instrument to manage its measuring sequence.
As far as I am concerned the program will have no user interface whatever but it will need to be running on command from cron and it must also detect if it has already started (some hints on this has been given in earlier threads).
Anyway, Lazarus gives a number of non-GUI selections for the new project:

1) Simple Program (A most simple FP command line program)
2) Program (A FP cmd line program with some useful settings added)
3) Console App (A FP cmd line program using TCustomApplication..)

I will probably need to use threads inside the program so I guess that 2 or 3 would be the appropriate selection.
Is there something else that may affect the decision? And what is the best selection between Program and Console Application?

Bo Berglund Developer in Sweden

Reply by email

Michael Schnell
to Bo Berglund
Bo Berglund wrote 11 lines
1) Simple Program (A most simple FP command line program) 2) Program (A FP cmd line program with some useful settings added) 3) Console App (A FP cmd line program using TCustomApplication..) I will probably need to use threads inside the program so I guess that 2 or 3 would be the appropriate selection. Is there something else that may affect the decision? And what is the best selection between Program and Console Application?

AFAIK, these three types don't feature different support for threads (i.e. none regarding Lazarus, but TTHread inherited from fpc)

IMHO, in fact for want you describe you will not need Lazarus library functionality at all, but of course it does make sense to use Lazarus as an IDE.

-Michael

Reply by email

Mark Morgan Lloyd
to Bo Berglund: I am finally ready to start creating my FPC/Lazarus control application based on a number…
Bo Berglund wrote 23 lines
I am finally ready to start creating my FPC/Lazarus control application based on a number of Delphi support units. The application is meant to be started on a Raspberry Pi2 by cron every minute or so and basically check if there is something to do and if not just exit. But if there is stuff to do it will create the needed control objects and start communicating with a data collection instrument to manage its measuring sequence. As far as I am concerned the program will have no user interface whatever but it will need to be running on command from cron and it must also detect if it has already started (some hints on this has been given in earlier threads). Anyway, Lazarus gives a number of non-GUI selections for the new project: 1) Simple Program (A most simple FP command line program) 2) Program (A FP cmd line program with some useful settings added) 3) Console App (A FP cmd line program using TCustomApplication..) I will probably need to use threads inside the program so I guess that 2 or 3 would be the appropriate selection. Is there something else that may affect the decision? And what is the best selection between Program and Console Application?

I'd be inclined to start with (2) in the general case, but I suggest that it would be worth experimenting, since the behaviour might vary depending on distro.

Be warned that you might find that your program might have a minimal PATH setting unless you run it from Dash or Bash (e.g. by putting it in a shell script), and you might need to redirect stdout and stderr since otherwise any output will probably be emailed to root.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]

Reply by email

Michael Van Canneyt
to Bo Berglund: I am finally ready to start creating my FPC/Lazarus control application based on a number…
Bo Berglund wrote 23 lines
I am finally ready to start creating my FPC/Lazarus control application based on a number of Delphi support units. The application is meant to be started on a Raspberry Pi2 by cron every minute or so and basically check if there is something to do and if not just exit. But if there is stuff to do it will create the needed control objects and start communicating with a data collection instrument to manage its measuring sequence. As far as I am concerned the program will have no user interface whatever but it will need to be running on command from cron and it must also detect if it has already started (some hints on this has been given in earlier threads). Anyway, Lazarus gives a number of non-GUI selections for the new project: 1) Simple Program (A most simple FP command line program) 2) Program (A FP cmd line program with some useful settings added) 3) Console App (A FP cmd line program using TCustomApplication..) I will probably need to use threads inside the program so I guess that 2 or 3 would be the appropriate selection. Is there something else that may affect the decision? And what is the best selection between Program and Console Application?

1 is suitable for small quick programs.

For anything that has a longer lifetime and is likely to change over the years, you should pick 3.

Michael.

Reply by email

Bo Berglund
to Michael Van Canneyt
Michael Van Canneyt wrote
For anything that has a longer lifetime and is likely to change over the years, you should pick 3.

Thanks, I did so and started coding. :)

Now I ran into a problem which I cannot say belongs to the selection of type of program or Lazaus itself or somethiong else:

I am building a communications class that will hook into the existing Delphi sources.
I write something like this:

TSSController = class
  private
    FComm: TSSConnection; //Defined in Delphi unit
  public
    Constructor Create(ConfigFile: string);
    Destructor  Destroy; override;
end;
destructor TSSController.Destroy;
begin
  FComm. <== cursor right after the period
  inherited Destroy;
end;

Where TSSConnection is declared in one of the Delphi files located in the same directory as all other sources (the project dir).

When I enter the period after FComm I expected Lazarus to autocomplete with the valid identifiers, in this case Free, but nothing happens...

My test project where I checked connectivity to the GPIO did not behave like this, but it was a GUI project. What did I do wrong?

Bo Berglund Developer in Sweden

Reply by email

Michael Van Canneyt
to Bo Berglund
Bo Berglund wrote 37 lines
On Mon, 19 Oct 2015 12:28:55 +0200 (CEST), Michael Van Canneyt wrote: > For anything that has a longer lifetime and is likely to change over the years, > you should pick 3. Thanks, I did so and started coding. :) Now I ran into a problem which I cannot say belongs to the selection of type of program or Lazaus itself or somethiong else: I am building a communications class that will hook into the existing Delphi sources. I write something like this: TSSController = class private FComm: TSSConnection; //Defined in Delphi unit public Constructor Create(ConfigFile: string); Destructor Destroy; override; end; destructor TSSController.Destroy; begin FComm. <== cursor right after the period inherited Destroy; end; Where TSSConnection is declared in one of the Delphi files located in the same directory as all other sources (the project dir). When I enter the period after FComm I expected Lazarus to autocomplete with the valid identifiers, in this case Free, but nothing happens... My test project where I checked connectivity to the GPIO did not behave like this, but it was a GUI project. What did I do wrong?

Did you add the files to the project in the project inspector dialog? That they are in the same directory as the project is not enough.

Michael.

Reply by email

Bo Berglund
to Michael Van Canneyt: Did you add the files to the project in the project inspector dialog? That they are in…
Michael Van Canneyt wrote
Did you add the files to the project in the project inspector dialog? That they are in the same directory as the project is not enough.

No, I just added them into the uses clause where appropriate. But I seem to remember from Delphi that the function was rather hit-and-miss in such cases. Having the units as part of the project made things much better!
Thanks for the pointer!

And I just realized that it probably will not work until the code can be compiled without errors too. And this does not happen because the Delphi/Windows stuff has to come out either by delete or a bunch of conditionals first. The compile barfs at such things as uses units like:
Windows,
comctrls,
extctrls,
Forms,
StdCtrls,
FileCtrl

I put these inside {$IFNDEF UNIX} blocks to get past the errors. Will have to deal later with the consequences of that of course.

One of the Delphi units (CommonFuncs) is a collection of goodies that is used by a number of the object units, however I have now decided to cut out everything not needed for this project from that unit and only keep the bare necessities.

First time I am doing anything seriously complex in Lazarus, only tested minute things over the years before (looked once a year perhaps).....

Bo Berglund Developer in Sweden

Reply by email