Recent

Author Topic: [NO SOLUTION] Case with string in Delphi mode  (Read 4793 times)

Okoba

  • Sr. Member
  • ****
  • Posts: 303
[NO SOLUTION] 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 := 'AAA';
  9.   case V of
  10.     'AAA': ;
  11.     'BBB': ;
  12.   end;
  13. end.    
« Last Edit: March 17, 2022, 01:23:43 pm by Okoba »

Jonas Maebe

  • Hero Member
  • *****
  • Posts: 963
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

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

wp

  • Hero Member
  • *****
  • Posts: 9592
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

  • Sr. Member
  • ****
  • Posts: 303
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: 474
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.  

Okoba

  • Sr. Member
  • ****
  • Posts: 303
Re: Case with string in Delphi mode
« Reply #6 on: March 16, 2022, 10:50:22 am »
Any updates on this?
Should I add a feature request on Gitlab?

wp

  • Hero Member
  • *****
  • Posts: 9592
Re: Case with string in Delphi mode
« Reply #7 on: March 16, 2022, 11:01:21 am »
In your code sample of the first post the strings had a length of only a single character. If this is true for your case in general then you could simple declare variable V as a char, and it should work in Delphi, too.
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Okoba

  • Sr. Member
  • ****
  • Posts: 303
Re: Case with string in Delphi mode
« Reply #8 on: March 16, 2022, 11:11:55 am »
Yes it can be used but the sample was misunderstood. I updated it.
For clarification I like to have the similar ability in objfpc mode for Delphi.

wp

  • Hero Member
  • *****
  • Posts: 9592
Re: Case with string in Delphi mode
« Reply #9 on: March 16, 2022, 11:21:13 am »
Should I add a feature request on Gitlab?
You can try, but I am rather sure that it will be rejected. Mode Delphi is intended to provide the same language features that Delphi has. But since Delphi has no "case of string", FPC won't have it in mode Delphi, either. Make a feature request with Embarcadero instead...
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

Okoba

  • Sr. Member
  • ****
  • Posts: 303
Re: Case with string in Delphi mode
« Reply #10 on: March 16, 2022, 11:23:31 am »
Its been years that I used Delphi.
I use Delphi mode only for the more clear/clean generic syntax. So I am stuck between features of objfpc and cleanness of delphi mode.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4014
  • Compiler Developer
Re: Case with string in Delphi mode
« Reply #11 on: March 17, 2022, 12:29:46 pm »
Any updates on this?
Should I add a feature request on Gitlab?

You already got a reply from Jonas Maebe who is a compiler dev and who said “No”. What more updates do you expect there?

Okoba

  • Sr. Member
  • ****
  • Posts: 303
Re: Case with string in Delphi mode
« Reply #12 on: March 17, 2022, 12:44:18 pm »
Considering what @bytebites pointed out, maybe a switch?
P.S. I did not know Jonas is a compiler dev.

Thaddy

  • Hero Member
  • *****
  • Posts: 11517
Re: Case with string in Delphi mode
« Reply #13 on: March 17, 2022, 01:01:15 pm »
Case of string is not supported by Delphi, period.
Most Delphi features are supported by FPC, but many features from fpc are not supported by Delphi.
(BTW: this feature lead to heavily contested discussions: imho it should not be there)
« Last Edit: March 17, 2022, 01:07:44 pm by Thaddy »
Путин преступник. Россияне дезинформированы.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4014
  • Compiler Developer
Re: Case with string in Delphi mode
« Reply #14 on: March 17, 2022, 01:08:55 pm »
Considering what @bytebites pointed out, maybe a switch?
P.S. I did not know Jonas is a compiler dev.

Jonas already said “No”. So, again, no.

 

TinyPortal © 2005-2018