Recent

Author Topic: Case with string in Delphi mode  (Read 1643 times)

Okoba

  • Full Member
  • ***
  • Posts: 249
Case with string in Delphi mode
« on: September 04, 2021, 10:14:19 am »
I can not find any option or switch to activate this option in Delphi mode. Is there one or can be one? I am using some Delphi only options (like the lighter generic syntax) so I prefer to remain with the Delphi mode for now.
Code: Pascal  [Select][+][-]
  1. program Project1;
  2.  
  3. {$MODE Delphi}
  4.  
  5. var
  6.   V: String;
  7. begin
  8.   V := 'A';
  9.   case V of
  10.     'A': ;
  11.     'B': ;
  12.   end;
  13. end.    

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 922
Re: Case with string in Delphi mode
« Reply #1 on: September 04, 2021, 10:48:04 am »
No, it cannot be enabled in Delphi mode (nor in TP or MacPas modes).

Okoba

  • Full Member
  • ***
  • Posts: 249
Re: Case with string in Delphi mode
« Reply #2 on: September 04, 2021, 10:52:59 am »
Pity.
Thanks.

wp

  • Hero Member
  • *****
  • Posts: 9040
Re: Case with string in Delphi mode
« Reply #3 on: September 04, 2021, 11:24:26 am »
The {$MODE} directive is per unit. So, if you somehow can concentrate all your "case string of" stuff in a separate unit you can use {$MODE objfpc}{$H+} there and {$MODE Delphi} elsewhere.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Okoba

  • Full Member
  • ***
  • Posts: 249
Re: Case with string in Delphi mode
« Reply #4 on: September 04, 2021, 12:28:31 pm »
Yes, but the problem of being in two modes keeps getting bigger and bigger.
Not having 'operator' in Delphi mode, or keep forcing them to write generic/specialize everywhere.
To be clear, I am not writing Delphi compatible code, but I like to have the lighter syntax of generics in the FPC mode, as in a heavy-generic code, generic/specialize makes everything seem more complicated than it really is. Also, in the coming of implicit generics, it would be much better to utilize generics in a light syntax.

bytebites

  • Sr. Member
  • ****
  • Posts: 424
Re: Case with string in Delphi mode
« Reply #5 on: September 05, 2021, 07:47:36 pm »
It is quite artificial limitation.
Find following code in the pstatmnt.pas file and do something to m_delphi-string. Then compile and install the compiler.

Code: Pascal  [Select][+][-]
  1.          caseofstring :=
  2.            ([m_delphi, m_mac, m_tp7] * current_settings.modeswitches = []) and
  3.            is_string(casedef);  
  4.  

 

TinyPortal © 2005-2018