Sign in Join

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

Mailing lists / lazarus / 2010-10

Getting a program's "true name"

11 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

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

Mark Morgan Lloyd

Is it possible to get the original name of a project by doing something like

scratch:= {$I %PROJFILE% };

I'm looking for an invariant identifier that I can use for a named pipe or unix-domain socket, irrespective of whether the binary has been renamed. I'd prefer not to stoop as far as hardcoding something.

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

Marco van de Voort
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote
Is it possible to get the original name of a project by doing something like scratch:= {$I %PROJFILE% };

Free Pascal doesn't know about projects, but can inline custom environment variables that way, if Lazarus would set them before running the compiler.

Reply by email

Mark Morgan Lloyd
to Marco van de Voort
Marco van de Voort wrote 7 lines
On Sun, Oct 24, 2010 at 01:38:42PM +0000, Mark Morgan Lloyd wrote: > Is it possible to get the original name of a project by doing something like > > scratch:= {$I %PROJFILE% }; Free Pascal doesn't know about projects, but can inline custom environment variables that way, if Lazarus would set them before running the compiler.
I use (*$IFDEF LCLGTK2 *) etc. in an "about" box, together with e.g.
(*$I %FPCVERSION% *) and (*$I %DATE% *).

Noting that somebody was asking about getting the LCL version a few days ago, where I've had to do this I tend to rely on having a fairly tight fit between FPC and LCL versions.

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

Marco van de Voort
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 9 lines
>> Is it possible to get the original name of a project by doing something like >> >> scratch:= {$I %PROJFILE% }; > > Free Pascal doesn't know about projects, but can inline custom environment > variables that way, if Lazarus would set them before running the compiler. I use (*$IFDEF LCLGTK2 *) etc. in an "about" box, together with e.g. (*$I %FPCVERSION% *) and (*$I %DATE% *).

An ifdef is a different beast from a {$i }. Defines are set on the cmdline (e.g. -dLCLGTK2 in the above case), while $I are

either built in (FPCVERSION, DATE, the easiest is to look up the
{$i %..%} syntax in the manual for a list)

_or_ an environmentvariable. This can be used to pass content like this, but means that lazarus has to set them in the environment that FPC calls.

The advantage of this, is that it will work with any 2.x FPC version.

Noting that somebody was asking about getting the LCL version a few days ago, where I've had to do this I tend to rely on having a fairly tight fit between FPC and LCL versions.

FPC doesn't know anything about LCL or Lazarus, let alone its exact versioning. But it can regurgitate information it gets passed _by_ Lazarus. Defines and {$I %environmentvariable%} are examples of this.

Reply by email

Mark Morgan Lloyd
to Marco van de Voort
Marco van de Voort wrote 21 lines
> I use (*$IFDEF LCLGTK2 *) etc. in an "about" box, together with e.g. > (*$I %FPCVERSION% *) and (*$I %DATE% *). An ifdef is a different beast from a {$i }. Defines are set on the cmdline (e.g. -dLCLGTK2 in the above case), while $I are either built in (FPCVERSION, DATE, the easiest is to look up the {$i %..%} syntax in the manual for a list) _or_ an environmentvariable. This can be used to pass content like this, but means that lazarus has to set them in the environment that FPC calls. The advantage of this, is that it will work with any 2.x FPC version. > Noting that somebody was asking about getting the LCL version a few days > ago, where I've had to do this I tend to rely on having a fairly tight > fit between FPC and LCL versions. FPC doesn't know anything about LCL or Lazarus, let alone its exact versioning. But it can regurgitate information it gets passed _by_ Lazarus. Defines and {$I %environmentvariable%} are examples of this.

The point I was trying to make- which I didn't do very well- was that if something is usable in an ifdef if can be used to exclude code which is syntactically wrong for the current compiler, or references public properties which don't exist in the current LCL.

I don't think that you can do that if you're getting a value from lclversion or whatever, the decision has- in effect- to be made at a preprocessor level.

Going back to my original question, can I put something like this

-dprojectname=heavy_wethers

or even

-dprojectname=$ProjFile()

in the project settings, and then use it as

projectName:= {$I %projectname% } ;
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

Marco van de Voort
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 23 lines
> versioning. But it can regurgitate information it gets passed _by_ Lazarus. > Defines and {$I %environmentvariable%} are examples of this. The point I was trying to make- which I didn't do very well- was that if something is usable in an ifdef if can be used to exclude code which is syntactically wrong for the current compiler, or references public properties which don't exist in the current LCL. I don't think that you can do that if you're getting a value from lclversion or whatever, the decision has- in effect- to be made at a preprocessor level. Going back to my original question, can I put something like this -dprojectname=heavy_wethers or even -dprojectname=$ProjFile() in the project settings, and then use it as projectName:= {$I %projectname% } ;

Not that I know. Via environment variables is the only way. I thought a while back to do this via macros ( -dxxx:=yyy syntax), so that it could also be on the cmdline:

http://bugs.freepascal.org/view.php?id=12935

Reply by email

Mattias Gaertner
to Marco van de Voort
Show quoted text 24 lines
On Mon, Oct 25, 2010 at 08:25:28AM +0000, Mark Morgan Lloyd wrote: > > versioning. But it can regurgitate information it gets passed _by_ Lazarus. > > Defines and {$I %environmentvariable%} are examples of this. > > The point I was trying to make- which I didn't do very well- was that if > something is usable in an ifdef if can be used to exclude code which is > syntactically wrong for the current compiler, or references public > properties which don't exist in the current LCL. > > I don't think that you can do that if you're getting a value from > lclversion or whatever, the decision has- in effect- to be made at a > preprocessor level. > > Going back to my original question, can I put something like this > > -dprojectname=heavy_wethers > > or even > > -dprojectname=$ProjFile() > > in the project settings, and then use it as > > projectName:= {$I %projectname% } ;

In project1.lpr add

uses FileUtil;
  ProjectName := ExtractFilenameOnly({$I %file%});
Show quoted text 5 lines
Not that I know. Via environment variables is the only way. I thought a while back to do this via macros ( -dxxx:=yyy syntax), so that it could also be on the cmdline: http://bugs.freepascal.org/view.php?id=12935

Mattias

Reply by email

Mark Morgan Lloyd
to Mattias Gaertner
Mattias Gaertner wrote 17 lines
>> Going back to my original question, can I put something like this >> >> -dprojectname=heavy_wethers >> >> or even >> >> -dprojectname=$ProjFile() >> >> in the project settings, and then use it as >> >> projectName:= {$I %projectname% } ; In project1.lpr add uses FileUtil; ProjectName := ExtractFilenameOnly({$I %file%});

Very nice- thanks for that.

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

Mark Morgan Lloyd
to Marco van de Voort: Not that I know. Via environment variables is the only way. I thought a while back to do…
Marco van de Voort wrote 17 lines
> Going back to my original question, can I put something like this > > -dprojectname=heavy_wethers > > or even > > -dprojectname=$ProjFile() > > in the project settings, and then use it as > > projectName:= {$I %projectname% } ; Not that I know. Via environment variables is the only way. I thought a while back to do this via macros ( -dxxx:=yyy syntax), so that it could also be on the cmdline: http://bugs.freepascal.org/view.php?id=12935

Ah- I hadn't thought of := on the command line :-) OK, situation as of 0.9.28.3 + 2.4.0 appears to be that the compiler ignores = (i.e. stores the whole thing as a shell variable) but breaks on := (i.e. stores the left-hand part only), however it only defines the shell variable, it doesn't assign it a value. Much the same for 27705 + 2.4.2-rc1 (I'm not complaining, only summarising).

Since := is significant in the -d option I wonder whether fpc -h should
be updated.

However the whole thing is slightly academic since Mattias has contributed his

Show quoted text 5 lines
In project1.lpr add uses FileUtil; ProjectName := ExtractFilenameOnly({$I %file%});

which looks like it will handle the project name issue perfectly.

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

Sven Barth
to Mark Morgan Lloyd: The point I was trying to make- which I didn't do very well- was that if something is…
Mark Morgan Lloyd wrote 8 lines
The point I was trying to make- which I didn't do very well- was that if something is usable in an ifdef if can be used to exclude code which is syntactically wrong for the current compiler, or references public properties which don't exist in the current LCL. I don't think that you can do that if you're getting a value from lclversion or whatever, the decision has- in effect- to be made at a preprocessor level.

Did you know that you can use Pascal constants (and thus the constants defined by lclversion unit) in {$if ...} conditionals? For an example see the "Button1Click" method in examples/lclversion/Unit1.pas.

Regards,
Sven

Reply by email