Solved

Pascal equivalent of VB Select/case

Posted on 2014-01-20
3
341 Views
Last Modified: 2014-01-20
Hi Experts,

its been a while since I have used Delphi and I feel silly for asking such a basic question but how the heck do you do a simple select case?

I have a function that returns a string and want to do something depening of the value:

IE

Select myString Case

'A': do this
'B': do that
else: do something else

end;

Thanks,
E.
0
Comment
Question by:etiennedemers
  • 2
3 Comments
 

Author Comment

by:etiennedemers
ID: 39796023
I try the Case command but I get Error E2001: Ordinal type required and its a string I want to use...
0
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39796034
Case only works with ordinals. But you can trick it using IndexStr. Something like

Case IndexStr (myString, ("A", "B")) of
  0: code; //A
  1: code; //B
  else: code;
end.

HTH,
Dan
0
 

Author Closing Comment

by:etiennedemers
ID: 39796060
Thank you Dan.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
help with delphi code 6 480
How to send email in delphi with image 4 588
audio record to file 4 1,094
Compare of Excelsheets 41 376
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
The question appears often enough, how do I transfer my data from my old server to the new server while preserving file shares, share permissions, and NTFS permisions.  Here are my tips for handling such a transfer.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

822 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