Recent

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

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: "$if declared()" directive
« Reply #15 on: December 02, 2021, 02:45:55 pm »
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.
...

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

Allowing that the context- at least of the thread as started- is .lpr files which are normally IDE-generated I presume mode ObjFPC applies.

The oldest FPC that I can possibly see myself running is 2.2.4 in order to run Lazarus building a GTK v1 app. I can't realistically see any reason I'd want to do that.

I do have one elderly 32-bit laptop which I use on occasion for testing comms hardware; because of old display hardware there's a complex kernel -> libraries -> apps progression which limits me to something like Lazarus 1.6.4 + FPC 3.0.2 on it hence the original question.

I think it's reasonable to assume that nobody will be running anything older, unless I (or anybody else) starts looking at e.g. SunOS/Solaris again where the available variant was- I think- limited to GTK1. I've done it in the past but really don't know how that squares with the versions above since Jonas et al. did various SPARC fixes around 2.7.1... it might be that I was able to use 2.7 or 3.0 on that platform but had to disable various packages.

A bit of looking at IDE sources earlier suggests that the other automatically-inserted line started appearing around Lazarus 1.0.0; in view of the combinations of Lazarus and FPC which realistically work together it is probably always safe to edit the .lpr to read

Code: Pascal  [Select][+][-]
  1. begin
  2. {$if LCL_FULLVERSION >= 1000000 }
  3.   RequireDerivedFormResource:=True;
  4. {$ifend                         }
  5. {$if LCL_FULLVERSION >= 1080000 }
  6.   Application.Scaled:=True;
  7. {$ifend                         }
  8.   Application.Initialize;
  9. ...
  10.  

Anything substantially older than Lazarus 1.0 is likely to have other problems caused by tabbed control and Synedit changes, plus possibly a change in the resource directive. But I'd be surprised if anybody seriously tried that and expected code that old to be portable without significant issues.

Thanks also to Alex.

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: 5446
  • Compiler Developer
Re: "$if declared()" directive
« Reply #16 on: December 03, 2021, 03:46:38 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.

3.0.0 would be the wrong place anyway, as the original feature was added in 2.0.x, but only for mode Delphi.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6676
Re: "$if declared()" directive
« Reply #17 on: February 19, 2022, 02:19:17 pm »
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... %)

I note that (as of 3.2.2) it does however accept a unit name:

Code: Pascal  [Select][+][-]
  1. { if declared(TMFRC522.PCD_PerformSelfTest) }  // Fails due to no dot etc. support
  2. {$if declared(mfrc522_diag) } // <----- Unit name (works)
  3. { if declared(TMFRC522H) }    // <----- Class helper in unit (works)
  4.       if mfrc522.PCD_PerformSelfTest() then
  5.         WriteLn('Selftest OK')
  6.       else
  7.         WriteLn('Selftest failed');
  8. {$endif                            }
  9.  

which is actually quite a comfortable way of handling things.

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

 

TinyPortal © 2005-2018