Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 17-06-2017
angelratza angelratza is offline
Registrado
NULL
 
Registrado: jun 2017
Posts: 8
Poder: 0
angelratza Va por buen camino
Error "Grid exceded index" en stringgrid

tengo un problema similar y con sus experiencia de que manera creen que podría lograrlo.

Tengo este código y al utilizar el IndexOf este me manda un error "Grid exceded index"

Código Delphi [-]
texto:=FVenta.EdVenta.Text;

IF GetTokenCount(texto,'%') = 2 then //cuando hay 2 tokens con signo de %
          begin
            if (EsStrunNumero(GetToken(texto,'%',1))) and (EsStrunNumero(GetToken(texto,'%',2)))then
            begin
              idesc:= StrToInt(GetToken(texto,'%',1));//Con esta funcion se obtiene el 1er. token que es el porcentaje de descuento y la colocamos a iDesc
              scve:= GetToken(texto,'%',2);   //Con esta Funcion se obtiene el 2o. token que es la clave de producto y se deposita en scve
              Fventa.SGVenta.Row := Fventa.SGVenta.Cols[1].indexOf(scve); // Con esta funcion nos posicionamos en la fila del producto

                MessageDlg(scve, mtInformation,[mbOk], 0);
                MessageDlg(Fventa.SGVenta.Cells[0,Fventa.SGVenta.Row], mtInformation,[mbOk], 0);

              if scve = Fventa.SGVenta.Cells[0,Fventa.SGVenta.Row] then // Verificamos que sea el producto seleccionado
              begin
                importdesc:=StrToFloat(Fventa.SGVenta.Cells[6,Fventa.SGVenta.Row]); // Obtenemos el valor del importe sin descuento
                if idesc <> 0 then
                begin
                  Desc:=1-idesc/100; //a 1 se resta el porcentaje de descuento para q Desc se multiplique por la cantidad
                  import:=importdesc*Desc;
                  Fventa.SGVenta.Cells[5,Fventa.SGVenta.Row]:= IntToStr(idesc); //Descuento
                end;

                import2:=FormatFloat('#,##0.00',DM1.QDist.FieldByName('Precio').AsFloat);//a Precio se le da formato
                Fventa.SGVenta.Cells[3,Fventa.SGVenta.Row]:= import2; //Precio

                import2:=FormatFloat('#,##0.00',import);
                Fventa.SGVenta.Cells[6,Fventa.SGVenta.Row]:= import2; //Importe

                if Fventa.EdImporte.Text <> '' then
                begin
                  importotal:=StrToFloat(QuitaEn(Fventa.EdImporte.Text, ','));
                  importotal:=importotal+import;
                  import2:=FormatFloat('#,##0.00',importotal);
                  Fventa.EdImporte.Text:=import2;
                  If Fventa.EdCostoEnvio.Text = '' then
                    Fventa.EdTotal.Text:=import2
                  else
                    Fventa.EdTotal.Text:=FormatFloat('#,##0.00',importotal+StrToFloat(Fventa.EdCostoEnvio.Text));
                end
                else
                begin
                  Fventa.EdImporte.Text:=import2;
                  If Fventa.EdCostoEnvio.Text = '' then
                    Fventa.EdTotal.Text:=import2
                  Else
                    Fventa.EdTotal.Text:=FormatFloat('#,##0.00',StrToFloat(import2)+StrToFloat(Fventa.EdCostoEnvio.Text)  );
                end;

                MessageDlg(FVenta.EdVenta.Text, mtInformation,[mbOk], 0);
                Fventa.EdVenta.Clear;

              end
              Else
              begin
                MessageDlg('El PRODUCTO solicitado no ha sido todavia ingresado', mtError,[mbOk], 0);
                FVenta.EdVenta.Clear;
              end;
            end
            Else
            begin
              MessageDlg('Revise su SINTAXIS', mtError,[mbOk], 0);
              FVenta.EdVenta.Clear;
            end;
          end;

Lo que se quiere lograr es encontrar en una columna un string especifico y obtener su indice para realizar las operaciones y sustituir valores.
Saludos.
Responder Con Cita
  #2  
Antiguo 17-06-2017
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.022
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
He movido tu pregunta a un nuevo hilo porque no tenía nada que ver con el hilo donde lo pusiste.
Responder Con Cita
  #3  
Antiguo 17-06-2017
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

En tu código, el único lugar donde usas la función IndexOf es en la línea:
Código Delphi [-]
...
  Fventa.SGVenta.Row := Fventa.SGVenta.Cols[1].indexOf(scve);
...
Pero... el error no puede provocarlo la función IndexOf ya que ella devuelve la posición en base cero, o -1 de no encontrar una ocurrencia. Por lo tanto el error debe ser provocado por el valor del índice usado en el TStrings Cols.

Para verificar (y visualizar) la validez del índice agrega lo siguiente:
Código Delphi [-]
// {$C+}
...
var
  inx: Integer;
begin
  inx := 1; 

  texto:=FVenta.EdVenta.Text;

  IF GetTokenCount(texto,'%') = 2 then
  begin
    if (EsStrunNumero(GetToken(texto,'%',1))) and (EsStrunNumero(GetToken(texto,'%',2)))then
    begin
      idesc:= StrToInt(GetToken(texto,'%',1));
      scve:= GetToken(texto,'%',2);

      if inx > SGVenta.ColCount-1 then
        raise Exception.CreateFmt('¡ Indice %d fuera de rango !%sSólo existen %d columnas',
                                  [inx, #13#10, SGVenta.ColCount-1]);
    
      Fventa.SGVenta.Row := Fventa.SGVenta.Cols[inx].indexOf(scve); 
  ...

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #4  
Antiguo 20-06-2017
angelratza angelratza is offline
Registrado
NULL
 
Registrado: jun 2017
Posts: 8
Poder: 0
angelratza Va por buen camino
Muchas gracias ECFISA, tenias razón estaba seleccionando mal la columna al especificarla en la propiedad cols.

Finalmente quedo así y funcionando.

Código Delphi [-]
Fventa.SGVenta.Row := Fventa.SGVenta.Cols[0].indexOf(scve);

Pues resulta que la columna en donde estaba buscando era la de cantidades (que es la columna numero 1) y no la de productos (que es la columna numero 0).

Por lo tanto al no encontrar el valor en dicha columna arroja el error "grid index out of range".
Responder Con Cita
  #5  
Antiguo 10-04-2021
Avatar de bulc
bulc bulc is offline
Miembro
 
Registrado: jun 2010
Posts: 412
Poder: 14
bulc Va por buen camino
Error Grid Out of range

El error que yo tenía lo solvente añadiendo:
DataSource1.DataSet := Nil;
DataSource1.DataSet := FDQuery1;
para abrir y cerrar el Dataset.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Mensaje "Index out of date" despues de ajecutar table1.emptytable cvlaso77 Tablas planas 5 19-08-2011 10:40:03
Error "Invalid index descriptor" marconm Conexión con bases de datos 0 16-03-2009 11:24:29
Problema con cliente servidor, error "xsqlda index out of range" Buelos Varios 0 18-07-2008 06:49:57
Error "List index out of bounds(7)" mamen .NET 2 24-01-2006 00:09:38
error al insertar campos "index of bounds(0)" carobahamondes MySQL 1 26-04-2005 01:40:24


La franja horaria es GMT +2. Ahora son las 12:57:59.


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
Copyright 1996-2007 Club Delphi