Solved

Greater/less than... in case statement?

Posted on 2006-07-06
3
662 Views
Last Modified: 2010-04-05
Hi,

My first question, so please bear with me... ;)

Does anyone know of a way to make case statements accept some construction of this kind:

case SomeInt of
  <10: DoSomething;
  10..1000: DoSomethingElse;
  >1000 DoSomethingDifferent;
end;

Yes, I can take a very high/low value for SomeInt (higher/lower than the highest/lowest expected value), like...

case SomeInt of
  -1000000..10: DoSomething;

...or even -2147483647, just to be sure :), and it will work, but it doesn't look/feel right.

BTW, I use D7 Pro.

Thanks!
0
Comment
Question by:TName
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Assisted Solution

by:geobul
geobul earned 100 total points
ID: 17052210
Hi,

Not possible using case statement. Another way is using if statements but you already know that, right?

if SomeInt < 10 then begin
  DoSomething;
end else begin
  if SomeInt >1000 then begin
    DoSomethingDifferent;
  end else begin
    DoSomethingElse;
  end;
end;

Regards, Geo
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 250 total points
ID: 17052615
hmm, kindof. you could use maxint

case SomeInt of
  10..1000: DoSomethingElse;
  1001..maxint: DoSomethingDifferent;
  else (*anything else is therefore < 10*) DoSomething
end;
0
 
LVL 28

Author Comment

by:TName
ID: 17053436

@ geobul:
Yes, I know about if statments (frantically nesting ifs was my first passion when I started coding :), but as I hadn't explicitly ruled out this solution, your hint is valid and so I increased the points, in order to be able to split them (I hope it's ok to do it...)

@TheRealLoki :
Even if it's the same thing "under the hood", it sure is a big improvement. It definitely looks nicer than typing huge numbers.
I didn't know about maxInt (hmm, coming to think of it, I could have declared such a constant myself...).
And now I see there are many of them already declared: "MinDouble", "MaxExtended"...

Thanks!
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to renew a Delphi rad-studio licence? 5 94
TServerSocket - file via sendbuf or Text via sendtext ? 1 90
Delphi inherited method 6 88
shape, triangle, dbctrlgrid 3 46
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question