Jump to content
PeterPanettone

A smart case statement in Delphi?

Recommended Posts

Hey folks. Some of you may know I've been working on AI with RemObjects, and that has exposed me to Oxygene significantly. I have been getting a bit of a "wow" reaction.

 

Oxygene can not only load and compile your Delphi projects (via LLVM, natively) but yes -- it has a case statement with strings.

 

You can even use a case statement as an expression, like the existing ternary operator on steroids.

 

https://blogs.remobjects.com/2025/09/10/texas-start-your-photocopiers/

  • Like 1

Share this post


Link to post

Congratulations. Wow you went on a double-dark side? (Remobjects and Pascal instead of  that other language).

 

PS. I wonder will Remobjects do anything with Pascal Script in near future? While Delphi is far behind other languages PS is also lagging.

Share this post


Link to post

I'm sorry, @Dave, but this subforum was never intended for advertising.
Changing companies is part of life, and it's not unusual to go to something like the competition. But honestly, you should be ashamed of your sarcastic blog post. It's in very poor taste and disappointing on a human level. Loyalty seems to have gone out of fashion, unfortunately. 
Be happy in your new job—but please refrain from advertising in places that are not intended for that purpose. There are subforums for that.

  • Like 1

Share this post


Link to post

If it can be of any help, case/switch In my "pet language" allows expressions at each case item. I choose the reserved keyword "when" just for fun, it can be another keyword in one second.

 

https://github.com/davidberneda/Vidi

 

// When. Multiple "ifs" (switch, case) 

 

  num ::= 5

  Console.PutLine(num)

  

  when num {

    < 3 { num:=123 }

  

     4 { num:=456 } // is num equal to 4?

 

     <>6 { Console.PutLine('num is not six') }

 

    // otherwise

    else {

      num *= 7 - 1

    }

  }

  

  Console.PutLine(num)

  

  // Works with any type

 

  when Name {

    "Jane" { Console.PutLine('Name is Jane') }

    "Peter" { Console.PutLine('Name is Peter') }

   // .Length=3 {} // TODO, use members "."

  }

 

  B : Text := 'b'

  

  when 'a'+B {

    "ab" { Console.PutLine('Text ab') }

  }

 

 

Edited by david berneda
< 3 ended up as a heart love emoji

Share this post


Link to post
5 hours ago, Daniel said:

I'm sorry, @Dave, but this subforum was never intended for advertising.
Changing companies is part of life, and it's not unusual to go to something like the competition. But honestly, you should be ashamed of your sarcastic blog post. It's in very poor taste and disappointing on a human level. Loyalty seems to have gone out of fashion, unfortunately. 
Be happy in your new job—but please refrain from advertising in places that are not intended for that purpose. There are subforums for that.

My apologies for seeming sarcastic. I understand why. I also know it's not intended as sarcasm. Text is hard and it's hard to balance the line of making points. I think it is wonderful when Delphi adds features, quite genuinely, and the post said so. I edited to try to help that understanding, but the original said "congratulations", and that is sincere, and I retained that comment.

 

It's hard reading that kind of reply, Daniel, and I don't know what to make of it. I think the best thing is to apologise because it's clear you are offended: and I am sorry for that.

 

Let me pontificate a bit: I worry about language compatibility. There are multiple Pascals out there: Free Pascal, DWScript, etc etc. Yet Pascal is a small language. If Delphi ever added any other feature Oxygene or Free Pascal or anyone else already has, and chose to do so with different, incompatible syntax, that would be a significant statement. I use Python a lot, it gives me the same "feeling" as Delphi when I use it, I have talked about Python a lot to people with quite some enthusiasm, it has a ternary if, and that ternary if is inverted -- that structure is legit, and Delphi could have used it, and then imagine if we had two versions in Pascal! Far better to copy, when it's already been done -- with code existing for years, it's key to keep the same syntax compatible. Equally, there's so much the language could do. When it moves forward, I hope it does so in ways that copy the path that has been led by others. Perhaps that is the message in the blog post: keep going; there's more, follow. I would certainly prefer it's read that way. Please read again, I hope it's gentler.

 

For this forum... that was not the message. I had intended to directly answer a thread about a language feature with a blog post showing a snippet of the language feature the OP asked for. Message: it is possible, look! I fully respect you don't want other implementations mentioned, and will respect that.

Edited by Dave Millington (personal)
  • Like 3

Share this post


Link to post
4 hours ago, david berneda said:

If it can be of any help, case/switch In my "pet language" allows expressions at each case item

It is of help actually -- I was feeling quite bad. Your post cheered me up.

 

Would you expand "when" to pattern matching?

 

  • Like 1

Share this post


Link to post
9 hours ago, Dave Millington (personal) said:

Oxygene can not only load and compile your Delphi projects (via LLVM, natively) but yes -- it has a case statement with strings.

Oxygene has plenty of features that would be great to have in Delphi. I wanted to have a case statement with strings for years now. I think it was even reported in the old, old Quality Central. If may look like a simple thing but it makes code more readable. Now when we got if expressions, maybe we wil eventually get case with strings, too.

  • Like 1

Share this post


Link to post
10 hours ago, Dave Millington (personal) said:

Oxygene can not only load and compile your Delphi projects (via LLVM, natively)

Yeah, sure...

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×