Recent

Author Topic: "$if declared()" directive  (Read 7715 times)

MarkMLl

  • Hero Member
  • *****
  • Posts: 3658
"$if declared()" directive
« on: November 27, 2021, 10:50:29 pm »
Somewhere around v2.0 Lazarus started adding an assignment to its .lpr file which breaks compatibility with older versions. How does one conditionalise it, since the example below doesn't work:

Code: Pascal  [Select][+][-]
  1.   RequireDerivedFormResource:=True;
  2. {$if declared(Application.Scaled) }
  3.   Application.Scaled:=True;
  4. {$endif                           }
  5.   Application.Initialize;
  6.  

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

wp

  • Hero Member
  • *****
  • Posts: 9157
Re: "$if declared()" directive
« Reply #1 on: November 27, 2021, 11:49:45 pm »
I think it came in v1.8. So, you can add LCLVersion to the uses clause of the project file and then put the Application.Scaled into an {$IF LCL_FullVersion >=1080000} directive:
Code: Pascal  [Select][+][-]
  1. begin
  2.   RequireDerivedFormResource:=True;
  3.   {$IF LCL_FullVersion >= 1080000}
  4.   Application.Scaled:=True;
  5.   {$IFEND}
  6.   Application.Initialize;
  7.   Application.CreateForm(TForm1, Form1);
  8.   Application.Run;
  9. end.    
But be warned: Sometimes the project file is rewritten by the IDE, and then the Application.Scaled := True will be re-added.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

MarkMLl

  • Hero Member
  • *****
  • Posts: 3658
Re: "$if declared()" directive
« Reply #2 on: November 28, 2021, 10:16:05 am »
Thanks very much for that, I'll investigate: I admit I didn't know about that define.

I routinely insert e.g. handlers for --help and --version into the .lpr just before that point, and /so/ /far/ haven't had the IDE interfere with it. In the current case the .lpr hadn't been rewritten, it was something I'd coded on a PC with a v2.0 IDE and then moved to a newly-rebuilt Raspberry Pi where the compiler and IDE were a bit older.

Slightly later for the record: that needs an explicit import of LCLVersion.

MarkMLl


« Last Edit: November 28, 2021, 10:43:53 am by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 9769
  • FPC developer.
Re: "$if declared()" directive
« Reply #3 on: November 28, 2021, 06:32:15 pm »
Maybe worth to try TApplication.scaled? 

MarkMLl

  • Hero Member
  • *****
  • Posts: 3658
Re: "$if declared()" directive
« Reply #4 on: November 28, 2021, 06:58:49 pm »
Maybe worth to try TApplication.scaled?

Regrettably not, I get

gui_test.lpr(51,5) Error: Evaluating a conditional compiling expression

Without meaning to criticise either project, I don't know which is worse: that Lazarus has added something without conditionalising it or that FPC complains about an undefined field without supporting the obvious way of excluding it.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 3638
  • Compiler Developer
Re: "$if declared()" directive
« Reply #5 on: November 30, 2021, 11:02:18 pm »
Without meaning to criticise either project, I don't know which is worse: that Lazarus has added something without conditionalising it or that FPC complains about an undefined field without supporting the obvious way of excluding it.

Declared() simply does not allow dots. It only allows identifiers (including generics) currently. I have it somewhere on my ToDo list to add support for dots as well, but we all know the problems with ToDo lists... %)

MarkMLl

  • Hero Member
  • *****
  • Posts: 3658
Re: "$if declared()" directive
« Reply #6 on: December 01, 2021, 07:01:22 am »
Without meaning to criticise either project, I don't know which is worse: that Lazarus has added something without conditionalising it or that FPC complains about an undefined field without supporting the obvious way of excluding it.

Declared() simply does not allow dots. It only allows identifiers (including generics) currently. I have it somewhere on my ToDo list to add support for dots as well, but we all know the problems with ToDo lists... %)

Indeed. As I said, I wasn't trying to criticise but I don't really know whose responsibility fixing that one is. It would have been easier if additions to automatically-inserted Lazarus code had been marked by a conditional.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 3638
  • Compiler Developer
Re: "$if declared()" directive
« Reply #7 on: December 01, 2021, 01:53:15 pm »
Indeed. As I said, I wasn't trying to criticise but I don't really know whose responsibility fixing that one is. It would have been easier if additions to automatically-inserted Lazarus code had been marked by a conditional.

Lazarus assumes that you're using a project generated with version X with version X or newer (here the version that generates a project with Application.Scaled does provide Application.Scaled as well). In my opinion that is a valid assumption.

MarkMLl

  • Hero Member
  • *****
  • Posts: 3658
Re: "$if declared()" directive
« Reply #8 on: December 01, 2021, 02:18:22 pm »
Lazarus assumes that you're using a project generated with version X with version X or newer (here the version that generates a project with Application.Scaled does provide Application.Scaled as well). In my opinion that is a valid assumption.

Somebody pointed out earlier in the thread that there is a risk that a given version of Lazarus insert lines into an older project.

I believe I've seen that, but I don't want to put my hand on my heart and say under what circumstances.

But I did say that the /easiest/ would have been if Lazarus conditionalised the addition, even if it were not strictly necessary.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Bart

  • Hero Member
  • *****
  • Posts: 4595
    • Bart en Mariska's Webstek
Re: "$if declared()" directive
« Reply #9 on: December 01, 2021, 02:23:25 pm »
There are some setting to treat a project with as much backwards compatibility as possible.
Maybe you can file a feature request to have it write that info in ifdef's based on that setting?

Bart

MarkMLl

  • Hero Member
  • *****
  • Posts: 3658
Re: "$if declared()" directive
« Reply #10 on: December 01, 2021, 02:49:45 pm »
There are some setting to treat a project with as much backwards compatibility as possible.
Maybe you can file a feature request to have it write that info in ifdef's based on that setting?

It's too late since it would be unreasonable to expect a fix to be backported.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Bart

  • Hero Member
  • *****
  • Posts: 4595
    • Bart en Mariska's Webstek
Re: "$if declared()" directive
« Reply #11 on: December 01, 2021, 05:29:11 pm »
At least it would not happen if you open the project in trunk then.

Bart

MarkMLl

  • Hero Member
  • *****
  • Posts: 3658
Re: "$if declared()" directive
« Reply #12 on: December 02, 2021, 01:03:17 pm »
I notice that the

Code: Pascal  [Select][+][-]
  1.   RequireDerivedFormResource:=True;
  2.  

line started being added about v1.0. Purely out of curiosity, can anybody say what version of FPC was first able to evaluate the

Code: Pascal  [Select][+][-]
  1.   {$IF LCL_FullVersion >= ...
  2.  

directive?

Please note that I'm not asking anybody to go looking for an answer, I can trawl through compiler release notes as easily as anybody. But if anybody knew from memory I'd be interested.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 3638
  • Compiler Developer
Re: "$if declared()" directive
« Reply #13 on: December 02, 2021, 01:53:57 pm »
Purely out of curiosity, can anybody say what version of FPC was first able to evaluate the

Code: Pascal  [Select][+][-]
  1.   {$IF LCL_FullVersion >= ...
  2.  

directive?

In mode Delphi since some time in the 2.0.x series, in mode ObjFPC since 2.2.0 and for all modes since 3.0.

Please note that I'm not asking anybody to go looking for an answer, I can trawl through compiler release notes as easily as anybody.

It can very well be that this isn't mentioned in the release notes. Not everything is mentioned there...

Alextp

  • Hero Member
  • *****
  • Posts: 1552
    • UVviewsoft
Re: "$if declared()" directive
« Reply #14 on: December 02, 2021, 02:05:23 pm »
Yes, it is not mentioned at https://wiki.freepascal.org/FPC_New_Features_3.0.0 as I see. I don't know how to 'formulate it' in the wiki.

 

TinyPortal © 2005-2018