Lazarus

Programming => LCL => Topic started by: Soner on April 22, 2019, 03:43:28 pm

Title: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: Soner on April 22, 2019, 03:43:28 pm
Is there for LCL compiler definition to gettting version number like this?
{$IF LCL_VERSION>2}
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: wp on April 22, 2019, 03:51:56 pm
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
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: jwdietrich on May 11, 2019, 11:30:17 pm
Unfortunately, this doesn't work.

Entering {$if LCL_FullVersion >= 2000000} ends up in the error message

Code: Pascal  [Select]
  1. 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.
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: wp on May 12, 2019, 12:01:04 am
You must add the unit in which LCL_FullVersion is defined to "uses".
Code: Pascal  [Select]
  1. uses
  2.   LCLVersion;
  3.  
  4. {$IF LCL_FullVersion >= 2000000}
  5.   {$DEFINE Something}
  6. {$IFEND}
 
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: jamie on May 12, 2019, 07:58:16 pm
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.
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: PascalDragon on May 15, 2019, 09:06:44 am
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.
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.
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: jwdietrich on May 15, 2019, 10:44:16 pm
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.

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.
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: dsiders on May 15, 2019, 11:33:57 pm
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.

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]
  1. uses
  2.   LazVersion,
  3.   LCLVersion;
  4.  
  5. { TForm1 }
  6.  
  7. procedure TForm1.Button1Click(Sender: TObject);
  8. begin
  9.  
  10. {$if laz_fullversion > 2000000}
  11. ShowMessage(IntToStr(laz_fullversion));
  12. {$endif}
  13. {$if LAZ_FULLVERSION > 2000000}
  14. ShowMessage(IntToStr(laz_fullversion));
  15. {$endif}
  16. {$IF lcl_fullversion > 2000000}
  17. ShowMessage(IntToStr(lcl_fullversion));
  18. {$ENDIF}
  19. {$IF LCL_FULLVERSION > 2000000}
  20. ShowMessage(IntToStr(lcl_fullversion));
  21. {$ENDIF}
  22.  
  23. end;
  24.  
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: jwdietrich on May 15, 2019, 11:42:05 pm
One 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.
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: dsiders on May 15, 2019, 11:49:10 pm
One 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.
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: wp on May 16, 2019, 12:38:27 am
Yes, 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).
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: Zoran on May 16, 2019, 02:23:51 am
I 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 (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.
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: 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.
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: PascalDragon on May 16, 2019, 08:53:57 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.
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: jamie on May 16, 2019, 11:06:25 pm
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.

Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: jwdietrich on May 17, 2019, 04:49:07 pm
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]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   ExtCtrls, LCLVersion
  10.   {$IF LCL_MAJOR >= 2}           // <- This doesn't work
  11.     , LazVersion
  12.   {$ENDIF}
  13.   ;
  14.  
  15. ...
  16.  
  17. implementation
  18.  
  19. ...
  20.  
  21. procedure TForm1.FormCreate(Sender: TObject);
  22. begin
  23.   {$IF LCL_MAJOR >= 2}              // <- This works
  24.     RadioGroup1.ItemIndex := 2;
  25.   {$ELSE}
  26.     {$IF LCL_MAJOR >= 1}
  27.       RadioGroup1.ItemIndex := 1;
  28.     {$ELSE}
  29.       RadioGroup1.ItemIndex := 0;
  30.     {$ENDIF}
  31.   {$ENDIF}
  32. end;
  33.  
  34. end.

This is a pity, since conditionals are much more needed at compile time than at runtime.
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: Zoran on May 17, 2019, 05:28:55 pm
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]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs,
  9.   LCLVersion
  10.   ;
  11.  
  12. {$if lcl_major >= 2}
  13. type
  14.   TSomething = Integer;
  15. {$endif}
  16.  
  17. type
  18.   TForm1 = class(TForm)
  19.   private
  20.  
  21.   public
  22.  
  23.   end;
  24.  
  25. var
  26.   Form1: TForm1;
  27.  
  28. implementation
  29.  
  30. {$R *.lfm}
  31.  
  32. end.
  33.  
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: wp on May 17, 2019, 06:57:28 pm
Or, if possible, put the conditionally excluded unit into the uses clause of the implementation section. This works for me:
Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   ExtCtrls, LCLVersion;
  10.  
  11. ...
  12.  
  13. implementation
  14.  
  15. {$IF LCL_MAJOR >= 2}
  16. uses
  17.   LazVersion;
  18. {$ENDIF}
  19.  
  20. ...
  21.  
Title: Re: Compiler definiton for lcl like {$IF LCL_VERSION>2} ?
Post by: jwdietrich on May 17, 2019, 11:21:29 pm
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.