Programming-Idioms

History of Idiom 162 > diff from v5 to v6

Edit summary for version 6 :
[Pascal] Comments conciseness

Version 5

2017-08-06, 16:26:46

Version 6

2017-09-01, 10:21:41

Idiom #162 Execute procedures depending on options

execute bat if b is a program option and fox if f is a program option.

Idiom #162 Execute procedures depending on options

execute bat if b is a program option and fox if f is a program option.

Code
function HasOption(c: char): Boolean;
var
  i: integer;
begin
  Result := False;
  for i := 1 to ParamCount do
    if (ParamStr(i) = ('-' + c)) then Exit(True);
end;  

begin
  if HasOption('b') then Bat;
  if HasOption('f') then Fox;
end.
Code
function HasOption(c: char): Boolean;
var
  i: integer;
begin
  Result := False;
  for i := 1 to ParamCount do
    if (ParamStr(i) = ('-' + c)) then Exit(True);
end;  

begin
  if HasOption('b') then Bat;
  if HasOption('f') then Fox;
end.
Comments bubble
The idiom does not state wether the options are exclusive.
I treated them as inclusive.
Comments bubble
Options may be combined.