Solved

Pascal equivalent of VB Select/case

Posted on 2014-01-20
3
343 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Background Information Recently I have fixed file server permission issues for one of my client. The client has 1800 users and one Windows Server 2008 R2 domain joined file server with 12 TB of data, 250+ shared folders and the folder structure i…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

821 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