[fpc-pascal]case .. with strings.
Michael Van Canneyt
michael.vancanneyt at wisa.be
Wed Feb 20 09:35:56 CET 2002
On Wed, 20 Feb 2002, jordi wrote:
> Hi, can someone help me?
>
> for example, if I have some constants :
>
> const
> name_1 : string [10] = 'abcdeefdre';
> name_2 : string [10] = 'gfsgeyeyey';
> name_3 : string [10] = 'jfmvnvyret';
> etc...
>
> Begin
> if paramstr (1) = name_1 then .....;
> if paramstr (1) = name_2 then ......;
> if paramstr (1) = name_3 then ......;
> etc...
>
> Is there another way to evaluate this constant strings?
> like : case paramstr (1) of
> name_1 : ...;
> name_2 : ....;
> name_3 : .....;
> end;
> the if sentence is very clear but if I have a lot of const values
> the program looks a little "stupid".
Case with strings is not supported, and probably will never be
supported. One way of doing the above is to
const
N = 3;
names : Array [1..N] string [10] = ('abcdeefdre','gfsgeyeyey','jfmvnvyret');
Var
I,Which : Integer;
begin
I:=1;
Which:=0;
While (Which=0) and (I<=N) do
If Names[I]=ParamStr(1) then
Which:=I
else
Inc(I);
Case Which of
1 : ;
2 : ;
3 : ;
else
// Zero, invalid option.
end
More information about the fpc-pascal
mailing list