Filtros Númericos

02/06/2003

0

Fiz um filtro onde vc digita : 1,2,3,4,5,6,7,8,9 ele devolve
1,2,3,4,5,6,7,8,9 se vc colocar 1,2-5,6,7-9 veja que tem o traço pois falta
os numero , ai ele faz a composição 1,2,3,4,5,6,7,8,9 , meu problema esta no
resultado quando ele devolve ele coloca 2 virgulas após o numero 5 , ficando
dessa maneira: 1,2,3,4,5,,6,7,8,9 . Não consegui identificar o erro . Se
alguém puder verificar e corrigir agradeço...

procedure TFrmFiltro.Button1Click(Sender: TObject);
begin
ShowMessage(GeraFiltro(Edit1.Text));
end;


function TFrmFiltro.GeraFiltro(const cFiltro: String): String;
var
nI,nJ:integer;
nInicio:integer;
cResult,cTemp : String;
begin
cResult := ´´;
cTemp := ´´;
nI:=1;
while nI <= length(cFiltro) do
begin
if cFiltro[nI] in [´0´..´9´] then
cTemp := cTemp + cFiltro[nI]
else
if cFiltro[nI] = ´-´ then
begin
nInicio := StrToInt(cTemp);
if Trim(cResult)<>´´ then cResult := cResult + ´,´;
cResult := cResult + cTemp;
cTemp := ´´;

if nI < length(cFiltro) then
begin
nJ := nI+1;
while (not (cFiltro[nJ] in [´-´,´,´,´ ´])) and (nJ<=length(cFiltro))
do
begin
cTemp := cTemp + cFiltro[nJ];
Inc(nJ);
Inc(nI); file://incrementa para percorrer a string
end;

if trim(cTemp)<>´´ then
for nJ:=nInicio+1 to StrToInt(cTemp) do
begin
if Trim(cResult)<>´´ then cResult := cResult + ´,´;
cResult := cResult + IntToStr(nJ);
end;
cTemp := ´´;
end;
end
else
if (cFiltro[nI] = ´,´) then
begin
if Trim(cResult)<>´´ then cResult := cResult + ´,´; file://Aqui loop 2
vezes
cResult := cResult + cTemp;
cTemp := ´´;
end;
Inc(nI);
end;

if trim(cTemp)<>´´ then
begin
if (Trim(cResult)<>´´) and (cResult[length(cResult)]<>´,´) then cResult
:= cResult + ´,´;
cResult := cResult + cTemp;
end;

Result := cResult;
end;

---

Desde já Agradeço pela atenção


Luizcesar

Luizcesar

Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

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

Aceitar