Fórum case string of --gt; Ordinal type requiered #210463
30/01/2004
0
var texto: string;
case texto of
´abc´:......
´def´:......
....
....
end;
daí dá o erro ´ordinal type requiered´......
q é isso?
::d::a::m::m::i::t::
Curtir tópico
+ 0Posts
30/01/2004
Tnaires
Resumindo: vc não pode usar case no delphi usando strings.
Tradução do help:
´... onde [i:d6d21ee0be]selectorExpression[/i:d6d21ee0be] é qualquer expressão do tipo Ordinal (tipos string são inválidos)...´
Té +
Gostei + 0
30/01/2004
Beppe
Gostei + 0
30/01/2004
Cebikyn
http://www.swissdelphicenter.ch/en/showcode.php?id=1028
Gostei + 0
30/01/2004
Bacalhau
Gostei + 0
30/01/2004
Beppe
O inconveniente é que as strings não poderão conter caracterers acentuados, espaços, etc...
Gostei + 0
30/01/2004
::d::a::m::m::i::t::
Gostei + 0
31/01/2004
Adilsond
And Yet Another Example of Case with Strings
By Henrik P. Hansen - hphansen@agora.dk
My solution is the function TokenNumber...
function TokenNumber(Source : string; const Delimeter, Token : string) : integer;
Here is an example of use...
{s = ?}
case TokenNumber(´CASE;ON;STRINGS;POSSIBLE;SOLUTION´, ´;´, s) of
1 : ShowMessage(´s = ´´CASE´´´);
2 : ShowMessage(´s = ´´ON´´´);
3 : ShowMessage(´s = ´´STRINGS´´´);
4 : ShowMessage(´s = ´´POSSIBLE´´´);
5 : ShowMessage(´s = ´´SOLUTION´´´);
else
ShowMessage(´s = unknown value´);
end;
Here comes the source for function TokenNumber...
function TokenNumber(Source : string; const Delimeter, Token : string) : integer;
var
i : integer;
begin
Result := 1;
while Result > 0 do {traverse through token´s in Source}
begin
i := Pos(Delimeter, Source);
if ((i > 0) and (Token = Copy(Source, 1, i - 1))) or
((i = 0) and (Token = Source)) then {if match then }
Break; { mission complete }
if i > 0 then {if more tokens then }
Delete(Source, 1, i + Length(Delimeter) - 1) { cut ´no match´ token }
else {else }
Result := -1; { mission complete }
Inc(Result);
end;
end;Gostei + 0
31/01/2004
Beppe
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)