Sign in Join
Wiki copytemporary

Show Application Title, Version, and Company: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## Overview
22
33### Windows
44
55From its earliest versions, Microsoft Windows had the capability of storing version information etc. in an executable file. Support for that was added to Delphi around v3, and was partly functional in Lazarus 0.9.24.
66
77### Linux
88
99There is no implicit provision in the ELF file format for version numbers, copyright and so on, but Lazarus stores this in resource sections. Reading the information back at runtime relies on FPC units, below is some useful information.
1010
1111### macOS and iOS
1212
1313On macOS, Lazarus file version information can be stored in two locations:
1414
1515- the MACH-O executable (like on Windows, Linux); see below
1616- the application bundle (if present) in a plist. See [[Mac Show Application Title, Version, and Company]] for details.
1717
1818## Implementations
1919
2020### FPC 3.0+
2121
2222Implementation in FPC 3.0.x using [[fcl-res]]: see [[User Changes 3.0|announcement in User Changes 3.0]].
2323
2424The code below shows how to get executable info out of:
2525
2626- .exe/.dll/.ocx files (Windows format)
2727- Lazarus-compiled ELF executables (Linux)
2828- Lazarus-compiled MACH-O executables (macOS)
2929
3030``` pascal
3131program printfileinfo;
3232
3333{
3434 Displays file version info for
3535- Windows PE executables
3636- Linux ELF executables (compiled by Lazarus)
3737- macOS MACH-O executables (compiled by Lazarus)
3838 Runs on Windows, Linux, macOS
3939}
4040
4141{$mode objfpc}{$H+}
4242{$ifdef mswindows}{$apptype console}{$endif}
4343uses
4444 {$IFDEF UNIX}{$IFDEF UseCThreads}
4545 cthreads,
4646 {$ENDIF}{$ENDIF}
4747 Classes,sysutils
4848 // FPC 3.0 fileinfo reads exe resources as long as you register the appropriate units
4949 , fileinfo
5050 , winpeimagereader {need this for reading exe info}
5151 , elfreader {needed for reading ELF executables}
5252 , machoreader {needed for reading MACH-O executables}
5353 ;
5454
5555var
5656 FileVerInfo: TFileVersionInfo;
5757
5858{$R *.res}
5959
6060begin
6161 FileVerInfo:=TFileVersionInfo.Create(nil);
6262 try
6363 FileVerInfo.ReadFileInfo;
6464 writeln('Company: ',FileVerInfo.VersionStrings.Values['CompanyName']);
6565 writeln('File description: ',FileVerInfo.VersionStrings.Values['FileDescription']);
6666 writeln('File version: ',FileVerInfo.VersionStrings.Values['FileVersion']);
6767 writeln('Internal name: ',FileVerInfo.VersionStrings.Values['InternalName']);
6868 writeln('Legal copyright: ',FileVerInfo.VersionStrings.Values['LegalCopyright']);
6969 writeln('Original filename: ',FileVerInfo.VersionStrings.Values['OriginalFilename']);
7070 writeln('Product name: ',FileVerInfo.VersionStrings.Values['ProductName']);
7171 writeln('Product version: ',FileVerInfo.VersionStrings.Values['ProductVersion']);
7272 finally
7373 FileVerInfo.Free;
7474 end;
7575end.
7676```
7777
7878### Implementations using legacy FPC 2.6.x
7979
8080Uses [[fcl-res]]; contribution via the mailing list: [1](http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20100723/8db6b97e/attachment.ksh)
8181
8282Use this like
8383
8484``` pascal
8585uses
8686 resource, versiontypes, versionresource;
8787
8888 FUNCTION resourceVersionInfo: STRING;
8989
9090 (* Unlike most of AboutText (below), this takes significant activity at run- *)
9191 (* time to extract version/release/build numbers from resource information *)
9292 (* appended to the binary. *)
9393
9494 VAR Stream: TResourceStream;
9595 vr: TVersionResource;
9696 fi: TVersionFixedInfo;
9797
9898 BEGIN
9999 RESULT:= '';
100100 TRY
101101
102102 (* This raises an exception if version info has not been incorporated into the *)
103103 (* binary (Lazarus Project -> Project Options -> Version Info -> Version *)
104104 (* numbering). *)
105105
106106 Stream:= TResourceStream.CreateFromID(HINSTANCE, 1, PChar(RT_VERSION));
107107 TRY
108108 vr:= TVersionResource.Create;
109109 TRY
110110 vr.SetCustomRawDataStream(Stream);
111111 fi:= vr.FixedInfo;
112112 RESULT := 'Version ' + IntToStr(fi.FileVersion[0]) + '.' + IntToStr(fi.FileVersion[1]) +
113113 ' release ' + IntToStr(fi.FileVersion[2]) + ' build ' + IntToStr(fi.FileVersion[3]) + eol;
114114 vr.SetCustomRawDataStream(nil)
115115 FINALLY
116116 vr.Free
117117 END
118118 FINALLY
119119 Stream.Free
120120 END
121121 EXCEPT
122122 END
123123 END { resourceVersionInfo } ;
124124```
125125
126126Using vinfo: [2](http://forum.lazarus.freepascal.org/index.php?topic=12435.0) and [3](http://forum.lazarus.freepascal.org/index.php?topic=13957.0)
127127
128128## Related tips
129129
130130### SVN/Git/Hg/Mercurial revision
131131
132132Use \$(lazarusdir)/tools/svn2revisioninc to get revision number (from a subversion, git or mercurial repository) into a file revision.inc, e.g. something like:
133133
134134``` pascal
135135// Created by Svn2RevisionInc
136136const RevisionStr = '43594';
137137```
138138
139139## Unix-only hacks
140140
141141These work with Linux on various platforms, and probably with Solaris provided that the GNU-derived utilities are installed.
142142
143143### Getting Subversion revision information as a program-accessible string
144144
145145Put this into Project options -\> Compilation -\> Execute before -\> Command:
146146
147-`` /bin/sh -c "echo -n C`svnversion -n`C |tr A-G %-+ >project_svnrevision.inc" ``
147+```text
148+/bin/sh -c "echo -n C`svnversion -n`C |tr A-G %-+ >project_svnrevision.inc"
149+```
148150
149151Note quote and backtick positions. The tr is converting C into another layer of quotes which is necessary for things to work as required.
150152
151153Put this into the program:
152154
153155``` pascal
154156 (*$IFDEF UNIX *)
155157 rev= (*$I project_svnrevision.inc *) ;
156158 (*$ELSE *)
157159 rev= 'unimplemented';
158160 (*$ENDIF *)
159161```
160162
161163Note that that has to be a string, since the revision number will have a non-numeric suffix if the project has been updated since it was last committed.
162164
163165### Renaming the final executable to include platform and timestamp
164166
165167Put this into Project options -\> Paths -\> Unit output directory:
166168
167-`lib/$(TargetCPU)-$(TargetOS)`
169+```text
170+lib/$(TargetCPU)-$(TargetOS)
171+```
168172
169173Put this into Project options -\> Paths -\> Target file name:
170174
171-`UnyokedBackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType)`
175+```text
176+UnyokedBackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType)
177+```
172178
173179Make sure that "Apply conventions" is ticked (checked). This might vary slightly according to IDE and compiler/linker versions.
174180
175181Put this into Project options -\> Compilation -\> Execute after -\> Command:
176182
177183``` bash
178184 /bin/sh -c "mv libunyokedbackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType).so UnyokedBackend-$(TargetCPU)-$(TargetOS)-$(LCLWidgetType).`date +%F.%R`.so"
179185```
180186
181187That should be a single line. Note quote and backtick positions.
182188
183189## See also
184190
185191- [[TVersionResource]]
186192
187193---
188194*From the Free Pascal wiki, page "Show Application Title, Version, and Company", as it stood on 2020-08-22 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
189195Category: Code
190196Category: FPC
191197Category: Lazarus
192198Category: Linux
193199Category: Windows
194200Category: macOS

Back to history