Sign in Join

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

Catalog · How the catalog works

Random project

POCI

Pascal Object Compiler Informations, a library for getting compiler informations (CPU, Target, Version...)

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

Pascal Object Compiler Information (POCI) is a code library. Its objective is to provide all the necessary elements to offer the possibility to know at runtime the compiler, the environment (Delphi, Lazarus, Typhon, the framework version. By generating these at the time of construction.

Using

To use the POCI library, simply include the poci.inc file in the project source file (*.ctpr, *.dpr, .ppr). The instruction is as follows:

pascal
{$i poci.inc}

Example :

pascal
program POCISample;
pascal
{$mode objfpc}{$H+}
pascal
uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  Classes, SysUtils, CustApp
  { you can add units after this };
pascal
...
pascal
{$i poci.inc}
pascal
...
pascal
type
pascal
{ TPOCISample }
pascal
TPOCISample = class(TCustomApplication)
protected
  procedure DoRun; override;
public
  constructor Create(TheOwner: TComponent); override;
  destructor Destroy; override;
  procedure WriteHelp; virtual;
end;
pascal
{ TPOCISample }
pascal
procedure TPOCISample.DoRun;
var
  ErrorMsg: String;
begin
  // quick check parameters
  ErrorMsg:=CheckOptions('h', 'help');
  if ErrorMsg<>'' then begin
    ShowException(Exception.Create(ErrorMsg));
    Terminate;
    Exit;
  end;
pascal
// parse parameters
if HasOption('h', 'help') then begin
  WriteHelp;
  Terminate;
  Exit;
end;
pascal
{ add your program here }
pascal
{ Using POCI constants declared }
WriteLN(Format('Compiler version : %s', [COMPILER_VERSION]));
WriteLN(Format('Framework name : %s', [FRAMEWORK_NAME]));
WriteLN(Format('Framework version : %s', [FRAMEWORK_VERSION]));
WriteLN(Format('Environment name : %s', [ENVIRONMENT_NAME]));
WriteLN(Format('Environment version : %s', [ENVIRONMENT_VERSION]));
pascal
// stop program loop
Terminate;
pascal
end;
pascal
constructor TPOCISample.Create(TheOwner: TComponent);
begin
  inherited Create(TheOwner);
  StopOnException:=True;
end;
pascal
destructor TPOCISample.Destroy;
begin
  inherited Destroy;
end;
pascal
procedure TPOCISample.WriteHelp;
begin
  { add your help code here }
  writeln('Usage: ', ExeName, ' -h');
end;
pascal
var
  Application: TPOCISample;
begin
  Application:=TPOCISample.Create(nil);
  Application.Title:='POCI Sample';
  Application.Run;
  Application.Free;
end.

Remarks

Ideally for the easiest use, it is better to have the files placed in an inclusion directory (Include) common to your projects. Access is relative. For example:

pascal
..\..\Include, on Windows ;
pascal
../../Include, on Linux.