Issue Details (XML | Word | Printable)

Key: CORE-5765
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Minor Minor
Assignee: Alexander Peshkov
Reporter: Tony Whyman
Votes: 1
Watchers: 3

If you were logged in you would be able to see more operations.
Firebird Core

Missing directives in Firebird.pas

Created: 04/Mar/18 02:56 PM   Updated: 25/Mar/18 06:19 AM
Component/s: API / Client Library
Affects Version/s: 3.0.3
Fix Version/s: 3.0.4, 4.0 Beta 1

Environment: Free pascal Compiler

QA Status: Cannot be tested

 Description  « Hide
In order to compile and use with FPC, the Firebird.pas file requires the following directives to be placed at the top of the file:

{$mode delphi}

If mode delphi is not specified then it will not compile unless this mode is specified on the command line.

If Objectchecks off is not specified then if the using program is compiled with the -CR debugging switch (Verify object method call validity) then a run-time error is reported whenever an attempt is made to call a Firebird 3 API method.

The Firebird.pas file in the source code distribution needs to be updated to include the above directives.

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Alexander Peshkov added a comment - 05/Mar/18 07:56 AM
What's the scope of this control comments in FPC - till the end of included file or wider?

Tony Whyman added a comment - 05/Mar/18 09:13 AM
Used in this way, it is simply to the end of file. (see

I only found out about the OBJECTCHECKS issue this weekend when an IBX user complained that the new release of IBX was failing with an "Invalid typecast". This was later found to be because he was debugging with all debug switches on. Putting this directive in the file allows users to use this debugging feature while still allowing use of the Firebird API.

When checking the 3.0.3 source I was surprised to find the "mode delphi" issue still not fixed as I am sure this came up on the lists ages ago. The IBX copy of Firebird.pas has had this directive in it since support for the Firebird 3 API was added.

Alexander Peshkov added a comment - 06/Mar/18 08:53 AM
Sorry by according to that docs MODE is global directive. I see no problems adding OBJECTCHECKS, but what a sense in adding MODE - what a sense with it if it's anyway global and will affect overall project?

But probably I'm missing something with Pascal project structure... (I do not use Pascal for last 30 years). Can you provide a sample of use of MODE DELPHI and desired content of firebird.pas?

Tony Whyman added a comment - 06/Mar/18 09:25 AM
The following is how I propose that the first few lines of Firebird.pas should look. Note that I have capitalised the $MODE DELPHI to look prettier - Pascal is case insensitive.

As to your question, and quoting from the FPC docs:

 "Global directives affect the whole of the compilation process of a single compilation unit (program, unit, library). They also have a command line counterpart, which is given for each of the directives. They must be specified before the first statement different from the program, unit or library clause in a source file, or they will have no effect. "

Be careful of the use of the word "program" here. In Pascal the "main" unit starts with "Program <program name>;", while normal source code modules start with "Unit <unitname>;", while the main unit for a DLL starts with "Library <libname>;". So when the above refers to a "Program", it is only referring to the main unit's source code and not to all units linked together to form a program.

Global Directives are global to the unit in which they are declared but have no affect on any unit that uses them. Unlike 'C' header files, Pascal declarations in the interfaces section are imported into other units as post compilation symbol tables rather than pre-compilation source code.

The use of the "MODE" directive in Firebird.pas is essential because Firebird.pas is a Delphi compliant source unit and has minor syntax differences from the default FPC Pascal dialect. However, there is no problem mixing Delphi compliant units and FPC compliant units in the same program given that the symbol information is imported post compilation rather than pre-compilation.

{ This file was autogenerated by cloop - Cross Language Object Oriented Programming }

unit Firebird;



uses Classes, SysUtils;

QWord = UInt64;

IVersioned = class;
IReferenceCounted = class;
IDisposable = class;
IStatus = class;
IMaster = class;
IPluginBase = class;
IPluginSet = class;
IConfigEntry = class;

Alexander Peshkov added a comment - 06/Mar/18 12:43 PM
Ahh - got it, the key here is that "there is no problem mixing Delphi compliant units and FPC compliant units in the same program".
Will fix.