Compiler definiton for lcl like {$IF LCL_VERSION>2} ? lazarus / 31-LCL ---------------------------------------------------------------------- Soner · 2019-04-22 13:43 Is there for LCL compiler definition to gettting version number like this? {$IF LCL_VERSION>2} ---------------------------------------------------------------------- wp · 2019-04-22 13:51 Not exactly like this: use LCL_FullVersion from unit LCLVersion, or Laz_FullVersion from unit LazVersion e.g.: {$IF LCL_FullVersion > 2030106}  // 2.03.01.06 ---------------------------------------------------------------------- jwdietrich · 2019-05-11 21:30 Unfortunately, this doesn't work. Entering {$if LCL_FullVersion >= 2000000} ends up in the error message 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 Error: Incompatible types: got "AnsiString" expected "Int64". Obviously LCL_FullVersion isn't defined. The code after {$if Declared(LCL_FullVersion) and (LCL_FullVersion >= 2000000)} is never compiled. ---------------------------------------------------------------------- wp · 2019-05-11 22:01 You must add the unit in which LCL_FullVersion is defined to "uses". 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 uses  LCLVersion; {$IF LCL_FullVersion >= 2000000}  {$DEFINE Something}{$IFEND} ---------------------------------------------------------------------- jamie · 2019-05-12 17:58 I've found that I need to CAPS the whole string.. {$IF FPC_FULLVERSION >= 30101} If I don't caps the string the compiler fails on it with an error stating it is expecting a Ansi string. I am doing this with 3.0.4 so that could be the difference. ---------------------------------------------------------------------- PascalDragon · 2019-05-15 07:06 Quote from: jamie on May 12, 2019, 07:58:16 pmI've found that I need to CAPS the whole string.. {$IF FPC_FULLVERSION >= 30101} If I don't caps the string the compiler fails on it with an error stating it is expecting a Ansi string. I am doing this with 3.0.4 so that could be the difference. Are you sure that you didn't misspell it in the other cases? Cause it works here in any casing (as it should) with both 3.0.4 and trunk. ---------------------------------------------------------------------- jwdietrich · 2019-05-15 20:44 Quote from: jamie on May 12, 2019, 07:58:16 pmI've found that I need to CAPS the whole string.. {$IF FPC_FULLVERSION >= 30101} If I don't caps the string the compiler fails on it with an error stating it is expecting a Ansi string. I am doing this with 3.0.4 so that could be the difference. Well, this is FPC_FULLVERSION. What is needed, however, is LCL_FULLVERSION. This still raises the type error, regardless of the case, in which the conditional is written. ---------------------------------------------------------------------- dsiders · 2019-05-15 21:33 Quote from: jwdietrich on May 15, 2019, 10:44:16 pmQuote from: jamie on May 12, 2019, 07:58:16 pmI've found that I need to CAPS the whole string.. {$IF FPC_FULLVERSION >= 30101} If I don't caps the string the compiler fails on it with an error stating it is expecting a Ansi string. I am doing this with 3.0.4 so that could be the difference. Well, this is FPC_FULLVERSION. What is needed, however, is LCL_FULLVERSION. This still raises the type error, regardless of the case, in which the conditional is written. One more time... You have to use the file that includes the version constants. Case does not matter. Try it. 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 uses  LazVersion,  LCLVersion; { TForm1 } procedure TForm1.Button1Click(Sender: TObject);begin {$if laz_fullversion > 2000000}ShowMessage(IntToStr(laz_fullversion));{$endif}{$if LAZ_FULLVERSION > 2000000}ShowMessage(IntToStr(laz_fullversion));{$endif}{$IF lcl_fullversion > 2000000}ShowMessage(IntToStr(lcl_fullversion));{$ENDIF}{$IF LCL_FULLVERSION > 2000000}ShowMessage(IntToStr(lcl_fullversion));{$ENDIF} end; ---------------------------------------------------------------------- jwdietrich · 2019-05-15 21:42 Quote from: dsiders on May 15, 2019, 11:33:57 pmOne more time... You have to use the file that includes the version constants. Yes, of course. But it doesn't work. Adding the uses clause with these units doesn't prevent this error message. ---------------------------------------------------------------------- dsiders · 2019-05-15 21:49 Quote from: jwdietrich on May 15, 2019, 11:42:05 pmQuote from: dsiders on May 15, 2019, 11:33:57 pmOne more time... You have to use the file that includes the version constants. Yes, of course. But it doesn't work. Adding the uses clause with these units doesn't prevent this error message. Alright then. Have fun with that. ---------------------------------------------------------------------- wp · 2019-05-15 22:38 Quote from: jwdietrich on May 15, 2019, 11:42:05 pmYes, of course. But it doesn't work. Adding the uses clause with these units doesn't prevent this error message. When you paste the dsiders' EXACT code into a button OnClick handler do you still get the same error? I do not get any error message - this code snippet is working correctly, I checked back to Laz 1.8.4 (Win 10). ---------------------------------------------------------------------- Zoran · 2019-05-16 00:23 Quote from: wp on May 16, 2019, 12:38:27 amI checked back to Laz 1.8.4 (Win 10). Actually, LazVersion didn't exist in 1.8.4, it was added in 2.0 (see https://bugs.freepascal.org/view.php?id=33418), but LCLVersion has been there for many years. Anyway, jwdietrich's signature says he's version is 2.0.0. And capitalization does not matter, of course. Dsiders' code works. ---------------------------------------------------------------------- jamie · 2019-05-16 01:20 @PascalDragging  Yes, I had to CAP the full string before it would work..  I found some sample code that did work and that is what was done, just a all CAPS and it worked.  Other combinations would report something like expecting some type but got Ansistring or the reverse. ---------------------------------------------------------------------- PascalDragon · 2019-05-16 06:53 Quote from: jamie on May 16, 2019, 03:20:16 am@PascalDragging  Yes, I had to CAP the full string before it would work..  I found some sample code that did work and that is what was done, just a all CAPS and it worked.  Other combinations would report something like expecting some type but got Ansistring or the reverse. Then please post a full example that does not work. It works here as both me and others confirmed. ---------------------------------------------------------------------- jamie · 2019-05-16 21:06 I can't make it happen in a simple program I found this when redoing a DX12.DX12 unit.. the compiler was interpreting it as a string and making then all CAPS fixed it.. I don't know what to tell  you but I know the compiler was confused. I'll get back to this when I open that project again but I know for a fact it was doing it. Today at the moment with simple code it isn't... Could be related to other units in the uses list. ---------------------------------------------------------------------- jwdietrich · 2019-05-17 14:49 I have now thoroughly checked this issue again with Lazarus versions 1.2.6, 1.6.2, 1.8.4 and 2.0.2 on Linux, macOS and Windows. If I use the LCL_FullVersion conditional (or some of its equivalents like LCL_MAJOR) in the implementation part everything works well. However, using it in the interface part raises the error as described. See a short example in the next section or in the attached file with a demo project. This project can only be compiled after commenting out lines 10 to 12 of unit1. 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 unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,  ExtCtrls, LCLVersion  {$IF LCL_MAJOR >= 2}           // <- This doesn't work    , LazVersion  {$ENDIF}  ; ... implementation ... procedure TForm1.FormCreate(Sender: TObject);begin  {$IF LCL_MAJOR >= 2}            // <- This works    RadioGroup1.ItemIndex := 2;  {$ELSE}    {$IF LCL_MAJOR >= 1}      RadioGroup1.ItemIndex := 1;    {$ELSE}      RadioGroup1.ItemIndex := 0;    {$ENDIF}  {$ENDIF}end; end. This is a pity, since conditionals are much more needed at compile time than at runtime. ---------------------------------------------------------------------- Zoran · 2019-05-17 15:28 Ah, I see now what you are trying to do. You are trying to use the constant before uses section ended. No, you can't do that. However, you can use it in interface section, but parser needs to finish the uses block before it can see the constants. This compiles well: 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 unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs,  LCLVersion  ; {$if lcl_major >= 2}type  TSomething = Integer;{$endif} type  TForm1 = class(TForm)  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} end. ---------------------------------------------------------------------- wp · 2019-05-17 16:57 Or, if possible, put the conditionally excluded unit into the uses clause of the implementation section. This works for me: 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 unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,  ExtCtrls, LCLVersion; ... implementation {$IF LCL_MAJOR >= 2}uses  LazVersion;{$ENDIF}  ... ---------------------------------------------------------------------- jwdietrich · 2019-05-17 21:21 Thanks, @Zoran and @wp. It works now. At least for me, a major issue that thwarted the evolution of one of my major projects is solved.