How to specify custom parsing mode ($M)? lazarus / 11-Options ---------------------------------------------------------------------- dredkin · 2015-12-09 10:23 Hello! FPC 3.0 inrtoduces new parsing mode: {$mode delphiunicode} I'm trying to compile my code with this mode on Lazarus 1.4.4, which does not have this value in parsing options. Can I specity this option for compiler somewhere in IDE (not in the code)? Adding -Mdelphiunicode to "Other Options" does not help. ---------------------------------------------------------------------- ChrisF · 2015-12-09 13:24 You can't with Lazarus 1.4.4, because it's using FPC 2.6.4. Unless you are using Free Pascal 3.x with your own Lazarus version 1.4.4 (?!). So, I can see 2 possibilities: - use trunk version (or test release 1.6 RC1) of Lazarus with Free Pascal 3.x, and put your option (-MDelphiUnicode) in 'Custom options' of the 'Compiler Options', - compile your code manually, calling directly the Free Pascal compiler. Note: I can't understand why you want to use this mode with Lazarus. I mean, Lazarus is currently not really supporting it. *** Edit *** 1/ The Lazarus IDE still adds is "own" compilation mode (Compiler Options -> Parsing -> Syntax mode), but apparently the latest (i.e. Custom Options in this case) is the winner with the Free Pascal compiler. For instance, this is giving a unicode executable: Quotefpc.exe -MObjFPC -MDelphiUnicode Test.pas 2/ This won't work with a Lazarus project (or any project using the LCL). You'll have to redefine the mode in each of your unit, in this case. ---------------------------------------------------------------------- dredkin · 2015-12-09 15:39 Yes I use FPC 3.0.0 built from sources with Lazarus also built from sources. I don't use LCL in my project so this won't be a problem. I cannot install 1.6RC1 .deb package because it reqiures fpc package to be installed while my FPC is built from sources. ANd I cannot instal fpc 3.0 .deb package because it always complains about binutils package not installed though it is actually. ---------------------------------------------------------------------- ChrisF · 2015-12-09 17:06 Well, if you are using Free Pascal 3.x, it should work using the 'Custom options'. The IDE is just forwarding these options to the Free Pascal compiler. For instance, for this sample program (but still using the Lazarus IDE): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; begin  {$ifdef UNICODE}  WriteLn('Unicode');  {$else}  WriteLn('Ansi');  {$endif}  ReadLn;end.  If I'm trying to compile it (Windows platform) with the -MDelphiUnicode 'custom options': Lazarus 1.4.4/FPC 2.6.4 Free Pascal compiler call from the IDE and response: QuoteCommand Line: Command Line: C:\lazarus\fpc\2.6.4\bin\i386-win32\fpc.exe -B -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -Fi[...My_Directory...]lib\i386-win32 -Fu[...My_Directory...] -FU[...My_Directory...]lib\i386-win32\ -MDelphiUnicode project1.lpr QuoteHint: (11030) Start of reading config file C:\lazarus\fpc\2.6.4\bin\i386-win32\fpc.cfg Hint: (11031) End of reading config file C:\lazarus\fpc\2.6.4\bin\i386-win32\fpc.cfg Error: (11006) Illegal parameter: -MDelphiUnicode Hint: (11007) -? writes help pages Error: C:\lazarus\fpc\2.6.4\bin\i386-win32\ppc386.exe returned an error exitcode (normal if you did not specify a source file to be compiled) Error: the Free Pascal compiler 2.6.4 doesn't know the -MDelphiUnicode parameter. Lazarus 1.5/FPC 3.0.0 QuoteCommand Line: C:\laztrunk\fpc\3.0.0\bin\i386-win32\fpc.exe -B -MObjFPC -Scghi -O1 -g -gl -l -vewnhibq -Fi[...My_Directory...]lib\i386-win32 -Fu[...My_Directory...] -FU[...My_Directory...]lib\i386-win32\ -MDelphiUnicode project1.lpr QuoteHint: (11030) Start of reading config file C:\laztrunk\fpc\3.0.0\bin\i386-win32\fpc.cfg Hint: (11031) End of reading config file C:\laztrunk\fpc\3.0.0\bin\i386-win32\fpc.cfg Free Pascal Compiler version 3.0.0 [2015/11/30] for i386 Copyright (c) 1993-2015 by Florian Klaempfl and others (1002) Target OS: Win32 for i386 (3104) Compiling project1.lpr [...My_Directory...]\project1.lpr(3,6) Hint: (5023) Unit "uuchar" not used in project1 (9015) Linking project1.exe (1008) 11 lines compiled, 0.9 sec, 33968 bytes code, 1316 bytes data (1022) 3 hint(s) issued OK: note that the call is identical, but this time the compiler has recognized and accepted the -MDelphiUnicode parameter. Finally, when the code in executed in this last case, the expected result is displayed (i.e. 'Unicode' displayed). So, if your compiler version (and platform) is accepting this parameter, you should got a positive result. ---------------------------------------------------------------------- ChrisF · 2015-12-10 13:28 BTW, if you plan to use non ASCII characters in your code, be sure to check your source code page property. Because the 'delphiunicode' mode switches the source code page: " ... the source file codepage is the DefaultSystemCodePage of the computer on which the compiler itself is currently running... ". See: http://wiki.freepascal.org/FPC_Unicode_support#Source_file_codepage. While the Lazarus IDE saves the source code in UTF-8 by default. So, add a '{$codepage UTF8}' mode in your source code units, or indicates it to the compiler AFTER the '-MDelphiUnicode' option. Like: -MDelphiUnicode -FcUTF8 (and not like: -FcUTF8 -MDelphiUnicode) Test program: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program project1; {$codepage UTF8} begin  {$ifdef UNICODE}  WriteLn('Unicode with special characters: éà ß Ññ');  {$else}  WriteLn('Ansi');  {$endif}  ReadLn;end. ---------------------------------------------------------------------- dredkin · 2015-12-14 13:13 Quote from: ChrisF on December 09, 2015, 06:06:20 pmWell, if you are using Free Pascal 3.x, it should work using the 'Custom options'. The IDE is just forwarding these options to the Free Pascal compiler. Unfortunately, Adding custom option does not help. Yes it sets $mode for all source files of my project, but it does not set it for standard fpc rtl units. As a result such a simple program won't compile: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; uses  strutils; var  S : string;begin  Copy2SymbDel(S,' ');end project1.lpr(11,17) Error: Call by var for arg no. 1 has to match exactly: Got "UnicodeString" expected "AnsiString" ---------------------------------------------------------------------- ChrisF · 2015-12-15 13:37 This is relative to FPC, not to the Lazarus IDE. Only a part of the RTL functions currently supports codepage (ansi) strings and/or unicode strings. See: http://wiki.freepascal.org/FPC_Unicode_support#RTL_changes Though it's possible a more recent version of FPC, like the trunk version, has some more (I don't know).