The good old case statement has one big handicap: You can not use it with strings as operators, only integers can be used. With a little tricky procedure, we can use strings as well as integers as operators for a case statement.

Look at this procedure:

function CaseString (const s: string; ci, p: Boolean; 
const x: array of string): Integer;
// s = the string to search for
// ci = when TRUE, the search is case insensitive
// p = when TRUE, s can be a part of the result string
// x = the possible strings in case statement
var i: Integer;
s1, s2: string;
Result:= -1;
if ci then s1:= AnsiUpperCase(s) else s1:= s;
for i:= Low (x) to High (x) do begin
if ci then
s2:= AnsiUpperCase(x[i])
s2:= x[i];
if p then begin
if Pos (s2, s1) > 0 then begin
Result:= i;
end else begin
if s1 = s2 then begin
Result:= i;

In fact we always have only integers in the case, but the function can scan the array of strings and return the index of the element searched for. This is a good example for the use of open arrays. In the parameter x, the possible strings for the case statement are given. For example:

var entry: string;

case CaseString (entry, TRUE, FALSE,
['YES','NO','CANCLE','FORMAT']) of
0: WriteString ('entry = yes');
1: WriteString ('entry = no');
2: WriteString ('entry = cancle');
3: WriteString ('entry = format');

parameter x can be a hand typed array or a array build at runtime, or - of course - a stringlist.