Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Conexión con bases de datos (https://www.clubdelphi.com/foros/forumdisplay.php?f=2)
-   -   Recorrer bd con parametros (https://www.clubdelphi.com/foros/showthread.php?t=92224)

johnny_jjc 30-08-2017 20:26:57

Recorrer bd con parametros
 
buenas amigos expertos.

tengo un problema.. tengo una tabla llamada 'VIGENCIAS' y unos campos con nombres >> 2010, 2011, 2012,.......2017.

quisiera recorrer los campos a travez de parametros.. actualmente los recorro con un CASE of
quisiera ahorrarme el CASE OF por un FOR vigencia=2010 to 2017

pero la instrucción >> TOTALAVALUOS:=TAvaluos[vigencia] >>> me genera error

podría alguien ilustrarme la forma debida?

mil gracias

roman 30-08-2017 20:44:13

:confused:

No entendí nada.

¿A qué te refieres con "campos con nombres"? ¿Los campos se llaman 2010, 2011, 2012,.......2017 o ésos son los valores de algún campo?

Un CASE es una intrucción de bifurcación de código mientras que un FOR es una instrucción de ciclo. ¿De qué manera podría una reemplazar a la otra?

¿Qué tiene que ver la asignación TOTALAVALUOS:=TAvaluos[vigencia] con todo lo demás que pones? Y ¿cuál es el error que genera?

Dedica más tiempo a formular la pregunta de una forma inteligible.

LineComment Saludos

johnny_jjc 31-08-2017 21:53:51

gracias Amigo roman.

te explico mas a detalle para tu gentil colaboracion.

Nombre tabla: AVALUOS
Campos
predio A 25
2010 N
2011 N
2012 N
2013 N
2014 N
2015 N
2016 N
2017 N
************************
Resultado: Llenar un Grid

Vigencia Avaluo Impuesto
2010 XXXX1 YYYYY1
2011 XXXX2 YYYYY2
........
2017 XXXX8 YYYYY8

********************************

Actualmente

NVigencias:=8;

FOR VANO:=1 TO NVigencias DO
BEGIN

GRIDLIQUIDACION.CELLS[1,I]:=inttostr(2010+I);


GRID:= GRIDLIQUIDACION.CELLS[1,I];

CASE GRID OF

//************ 2010

2010: begin
GRIDLIQUIDACION.CELLS[2,I]:=strtoint(TAvaluos['2010']);
GRIDLIQUIDACION.CELLS[3,I]:=CALCULARIMPUESTO(TAvaluos['2010']);
end;

EN TOTAL SON 8 VIGENCIAS >>> OBSERVANDO PODRIA REDUCIR TODO EL CASE DE LA SIGUIENTE MANERA:

FOR VVIGENCIA:=2010 TO 2017
begin
GRIDLIQUIDACION.CELLS[2,I]:=strtoint(TAvaluos[VVIGENCIA]);
GRIDLIQUIDACION.CELLS[3,I]:=CALCULARIMPUESTO(TAvaluos[VVIGENCIA]);
end;

PERO ME MARCA ERROR >>> QUISIERA REEMPLAZAR TAvaluos['2010'] POR TAvaluos[VVIGENCIA]
COMO RREMPLAZO EN NOMBRE DEL CAMPO POR UN PARAMETRO????....

Casimiro Notevi 31-08-2017 22:11:10

Por favor, lee nuestra guía de estilo, gracias :)

Y para otras ocasiones, recuerda poner los tags al código fuente, ejemplo:



Gracias :)

duilioisola 01-09-2017 14:28:27

Por lo que entiendo el campo se llama '2010'. '2011', etc.
Si TAValuous['2010'] es la forma de llamar al contenido del campo, entonces tienes que pasarle un string como índice.
Quedaría algo así:

Código Delphi [-]
FOR VVIGENCIA:=2010 TO 2017 DO
begin
   GRIDLIQUIDACION.CELLS[2,I] := StrToInt(TAvaluos[IntToStr(VVIGENCIA)]);
   GRIDLIQUIDACION.CELLS[3,I] := CALCULARIMPUESTO(TAvaluos[IntToStr(VVIGENCIA)]);
end;

o un poco mas claro
Código Delphi [-]
var
   Vigencia : integer;
   NombreCampo : string;

[...]

FOR Vigencia := 2010 TO 2017 DO
begin
   // El nombre del campo corresponde con el valor de vigencia
   NombreCampo := IntToStr(Vigencia);

   // Paso datos de la tabla al grid.
   GRIDLIQUIDACION.CELLS[2,I] := StrToInt(TAvaluos[NombreCampo]);
   GRIDLIQUIDACION.CELLS[3,I] := CALCULARIMPUESTO(TAvaluos[NombreCampo]);
end;


La franja horaria es GMT +2. Ahora son las 04:44:53.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi