Recent

Author Topic: Dynamic array extensions ?  (Read 8638 times)

taazz

  • Hero Member
  • *****
  • Posts: 5363
Re: Dynamic array extensions ?
« Reply #30 on: June 21, 2018, 10:00:10 pm »
Quote
Addendum to that: the "+" operator is now connected to a "ArrayOperators" modeswitch.

Thank you. Guess that is an acceptable solution.

Code: Pascal  [Select]
  1. {$modeswitch ArrayOperators-} // Note the "-"
Why is it "-" in this case rather than "OFF" ?
As far as I understand, + is an alias to on,  - an alias to off, (or vice versa) they are interchangeable, he only drawn your attention to the - because it is easy to miss, if he had used off instead then the note would not have been necessary.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

VTwin

  • Hero Member
  • *****
  • Posts: 585
  • Former Turbo Pascal 3 user
Re: Dynamic array extensions ?
« Reply #31 on: June 22, 2018, 06:43:03 pm »
Quote
Addendum to that: the "+" operator is now connected to a "ArrayOperators" modeswitch.

Thank you. Guess that is an acceptable solution.

Code: Pascal  [Select]
  1. {$modeswitch ArrayOperators-} // Note the "-"
Why is it "-" in this case rather than "OFF" ?

https://www.freepascal.org/docs-html/prog/progsu105.html

Quote
The syntax is as follows:
{$MODESWITCH XXX} 
{$MODESWITCH XXX+} 
{$MODESWITCH XXX-}

The first two will switch on feature XXX, the last one will switch it off.

A mode switch seems like a good solution. Thanks!
“Talk is cheap. Show me the code.” -Linus Torvalds

macOS 10.11.6: Lazarus 2.0.1 svn r60659 (64 bit Cocoa)
Ubuntu 18.04.2: Lazarus 2.0.0 (64 bit on VBox)
Windows 7 Pro SP1: Lazarus 2.0.0 (64 bit on VBox)

PascalDragon

  • Sr. Member
  • ****
  • Posts: 284
  • Compiler Developer
Re: Dynamic array extensions ?
« Reply #32 on: June 22, 2018, 10:36:52 pm »
Quote
Addendum to that: the "+" operator is now connected to a "ArrayOperators" modeswitch.

Thank you. Guess that is an acceptable solution.

Code: Pascal  [Select]
  1. {$modeswitch ArrayOperators-} // Note the "-"
Why is it "-" in this case rather than "OFF" ?

Because modeswitches currently don't support ON/OFF, only +/- (the latter can also be used with other switches, like e.g. $ScopedEnums).  :-[

ASBzone

  • Full Member
  • ***
  • Posts: 148
  • Automation leads to relaxation...
    • BrainWaveCC Utilities
Re: Dynamic array extensions ?
« Reply #33 on: June 23, 2018, 01:31:03 am »
Addendum to that: the "+" operator is now connected to a "ArrayOperators" modeswitch.

If the modeswitch is active then the "+" operator overload is not possible and the compiler will warn if such an overload is in scope. If the modeswitch is not set, then everything is as before.

The modeswitch is enabled by default in Delphi modes, because that's why the feature was added. To disable the modeswitch there use this:

Code: Pascal  [Select]
  1. {$mode Delphi}
  2. {$modeswitch ArrayOperators-} // Note the "-"

Awesome.  Much appreciated.
-ASB: https://www.BrainWaveCC.com

Lazarus v2.0.1 r60647 / FPC v3.2.0-beta-r41629 (via FpcUpDeluxe)
-- 64-bit install w/32-bit cross-compile
Primary System: Windows 10 Pro x64, Version 1809 (Build 17763.195)
Other Systems: Windows 10 Pro x64, Version 1803 or greater

PascalDragon

  • Sr. Member
  • ****
  • Posts: 284
  • Compiler Developer
Re: Dynamic array extensions ?
« Reply #34 on: June 23, 2018, 01:49:56 pm »
Because modeswitches currently don't support ON/OFF, only +/- (the latter can also be used with other switches, like e.g. $ScopedEnums).  :-[

And now FPC also supports ON and OFF in modeswitches :D