* * *

Author Topic: [SOLVED] Change default compiler mode directive?  (Read 1079 times)

knuckles

  • Full Member
  • ***
  • Posts: 100
[SOLVED] Change default compiler mode directive?
« on: March 29, 2017, 05:32:43 pm »
Since installing and upgrading to Lazarus 1.7 from https://www.getlazarus.org/setup/ ive noticed new projects and source files are using:

Code: Pascal  [Select]
  1. {$mode delphi}

Is there a global setting somewhere I can change to always make sure new source files use the following instead?
Code: Pascal  [Select]
  1. {$mode objfpc}{$H+}
« Last Edit: March 31, 2017, 08:15:38 pm by knuckles »

Thaddy

  • Hero Member
  • *****
  • Posts: 4651
Re: Change default compiler mode directive?
« Reply #1 on: March 29, 2017, 05:54:11 pm »
No.
These compiler settings work on a per unit basis and since FPC supports them like that there is really no need to change it.
A good example would be using generics: If the unit that implements a generic is implemented in objfpc generics mode you can use it in your own code in delphi generics mode.
I use that all the time. It is transparent between all the modes that support object orientation.

This is a major feature, not something that you would want to be changed in any way.
If you use any unit of the FPC and Lazarus provided units, you are free to choose any mode you like for your own code.
« Last Edit: March 29, 2017, 05:56:54 pm by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 184
Re: Change default compiler mode directive?
« Reply #2 on: March 29, 2017, 06:34:35 pm »
Yes, there is. Just change the compiler mode for your project and Lazarus will automatically adjust new files for you. If the project main file and project options differ you get the dialog from the attachment when creating a new file.

howardpc

  • Hero Member
  • *****
  • Posts: 2400
Re: Change default compiler mode directive?
« Reply #3 on: March 29, 2017, 06:44:27 pm »
In the Lazarus IDE you can set particular compiler options as the default settings.
Choose the Project->Project Options... menu (Ctrl+Shift+F11 is the default shortcut) to display the Options for Project: xxx dialog.
The default mode set for all project units is shown under
Compiler Options
  Parsing

in the treeview on the left.
You want the dropdown labelled "Syntax mode{-M, {$MODE}}"
You want to ensure the dropdown is set to
  "Object Pascal - default (-MObjFPC).

If you tick the checkbox at the bottom labelled "Set compiler options as default" before clicking the OK button, this will make sure that new projects are populated with skeleton code including your preferred mode.
If you still get the 'wrong' mode in new units, it's also worth checking the setting in your fpc.cfg file, in case this conflicts.

knuckles

  • Full Member
  • ***
  • Posts: 100
Re: Change default compiler mode directive?
« Reply #4 on: March 31, 2017, 08:15:25 pm »
Great thanks everyone  :)

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus