case string of --gt; Ordinal type requiered
no comando case of, quando eu coloco uma string...por exemplo...
var texto: string;
case texto of
´abc´:......
´def´:......
....
....
end;
daí dá o erro ´ordinal type requiered´......
q é isso?
var texto: string;
case texto of
´abc´:......
´def´:......
....
....
end;
daí dá o erro ´ordinal type requiered´......
q é isso?
::d::a::m::m::i::t::
Curtidas 0
Respostas
Tnaires
30/01/2004
Olá dammit
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é +
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
Beppe
30/01/2004
Você pode usar if´s encadeados, ou colocar numa stringlist e chamar IndexOf ou Find.
GOSTEI 0
Cebikyn
30/01/2004
[b:d56436a685]How to use Strings in a Case Statement[/b:d56436a685] - em Inglês:
http://www.swissdelphicenter.ch/en/showcode.php?id=1028
http://www.swissdelphicenter.ch/en/showcode.php?id=1028
GOSTEI 0
Bacalhau
30/01/2004
Depois dessa do Cebikyn fico sem palavras. Tem horas que eu fico pensando: ´Não percebo mesmo nada disto...´ Aquele artigo é 5 estrelas
GOSTEI 0
Beppe
30/01/2004
[b:4c1c117ed7]How to use Strings in a Case Statement[/b:4c1c117ed7] - em Inglês:
http://www.swissdelphicenter.ch/en/showcode.php?id=1028
O inconveniente é que as strings não poderão conter caracterers acentuados, espaços, etc...
GOSTEI 0
::d::a::m::m::i::t::
30/01/2004
valew galera..... :lol:
GOSTEI 0
Adilsond
30/01/2004
The Unofficial Newsletter of Delphi Users - http://www.undu.com
And Yet Another Example of Case with Strings
By Henrik P. Hansen - hphansen@agora.dk
My solution is the function TokenNumber...
Here is an example of use...
Here comes the source for function TokenNumber...
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
Beppe
30/01/2004
Mas por performance, usem uma stringlist, ou uma tabela de hash.
GOSTEI 0