GARANTIR DESCONTO

Fórum case string of --gt; Ordinal type requiered #210463

30/01/2004

0

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?


::d::a::m::m::i::t::

::d::a::m::m::i::t::

Responder

Posts

30/01/2004

Tnaires

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é +


Responder

Gostei + 0

30/01/2004

Beppe

Você pode usar if´s encadeados, ou colocar numa stringlist e chamar IndexOf ou Find.


Responder

Gostei + 0

30/01/2004

Cebikyn

[b:d56436a685]How to use Strings in a Case Statement[/b:d56436a685] - em Inglês:
http://www.swissdelphicenter.ch/en/showcode.php?id=1028


Responder

Gostei + 0

30/01/2004

Bacalhau

Depois dessa do Cebikyn fico sem palavras. Tem horas que eu fico pensando: ´Não percebo mesmo nada disto...´ Aquele artigo é 5 estrelas


Responder

Gostei + 0

30/01/2004

Beppe

[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...


Responder

Gostei + 0

30/01/2004

::d::a::m::m::i::t::

valew galera..... :lol:


Responder

Gostei + 0

31/01/2004

Adilsond

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...

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;



Responder

Gostei + 0

31/01/2004

Beppe

Mas por performance, usem uma stringlist, ou uma tabela de hash.


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar