Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 15-02-2007
fergape fergape is offline
Miembro
 
Registrado: oct 2005
Posts: 19
Poder: 0
fergape Va por buen camino
Error en ejecucion

tengo un pequeño modulo en un sistema donde hago una exportacion a excel de una consulta. cuando ejecuto la exportacion me salta el siguiente error "Access Violation at address 042A1617 in modulo 'libreria.dll'.Read of address 00000000."

este modulo se divide en tres consultas con sus respectivas exportaciones a excel y hay dos que funcionan bien, y una de esas que funcionan es exactamente igual, con algunas variantes de SQL, a la que tendria que andar pero no anda y no es un problema de sql.. si alguien me puede dar una idea o ayuda les voy a agradecer...
Responder Con Cita
  #2  
Antiguo 15-02-2007
Avatar de vtdeleon
vtdeleon vtdeleon is offline
Miembro
 
Registrado: abr 2004
Ubicación: RD & USA
Posts: 3.236
Poder: 24
vtdeleon Va por buen camino
Y el Código? Muenstralo.

Saludos
__________________
Van Troi De León
(Not) Guía, Code vB:=Delphi-SQL, ¿Cómo?
Viajar en el tiempo no es teóricamente posible, pues si lo fuera, ya estarían aqui contándonos al respecto!
Responder Con Cita
  #3  
Antiguo 15-02-2007
fergape fergape is offline
Miembro
 
Registrado: oct 2005
Posts: 19
Poder: 0
fergape Va por buen camino
La parte de código que esta en rojo es una exportacion y esa funciona de 10 y la de codigo azul es otra exportacion y es la que no funciona..

Código Delphi [-]
procedure Trf_IncDocAAN.btnExportarClick(Sender: TObject);
var
LineNumber, LCID : Integer;
LineString : String;
begin
inherited;
if radiogroup1.ItemIndex = 0 then
begin
with SaveDialog1 do
begin
FileName := '';
Filter := 'Excel files|*.XLS;All Files|*.*';
DefaultExt := 'xls';
Title := 'Exportando a Excel';
if execute then
begin
qryIncDocmensual.Open;
LCID := GetUserDefaultLCID;
with ExcelApplication1 do
begin
connect;
try
visible[LCID] := true;
Workbooks.Add(EmptyParam,LCID);
Range['A1','T1'].Value2 := VarArrayOf(['Mes','Documento','Apellido y Nombre','Rama de Enza.','Código del cargo','Carga Horaria','Tipo De Cargo',
'Sit. de revista','Subv.','Asist.','Código Liquid./ Clave Identif.','Clave Identif.','Haberes Brutos','Haberes Líquidos','Años A.',
'Obra Soc.','Sexo','Cuil','CUE','Niveles de Enza.']);
// se definen formatos de las celdas
with Range['A1','T1'] do
begin
HorizontalAlignment := xlcenter;
VerticalAlignment := xlBottom;
Wraptext := false;
orientation := 0;
ShrinkTofit := false;
MergeCells := false;
font.Bold := true;
end;
qryIncDocMensual.First;
LineNumber := 1;
//envia datos a excel
while not qryIncDocMensual.Eof do
begin
//antiguedad
if qryIncDocMensualtotalAntig.IsNull then
antiguedad := qryIncDocMensualAntig.Value
else
antiguedad := qryIncDocMensualtotalAntig.Value;
// horas del cargo
hscarga := qryIncDocMensualhoras_carga.AsInteger;
if hscarga < 10 then
hs := '''0'+inttostr(hscarga)+'00'
else
hs := inttostr(hscarga)+'00';
if qryIncDocMensualhoras_carga.AsInteger <= 0 then
hstotal:= inttostr(qryIncDocMensualcarga_c.AsInteger)
else
hstotal := hs;
//DNI
if strtoint(trim(qryIncDocMensualdni.Value)) < 10000000 then
dni := qryIncDocMensualsexodni.Value
else
dni :=qryIncDocMensualdni.AsString;
//cambio de periodo en el mes con el retroactivo
if qryIncDocMensualperiodoRetro.IsNull then
periodo := qryIncDocMensualperiod.AsInteger
else
periodo := qryIncDocMensualPeriodoRetro.Value;
Inc(LineNumber);
LineString := IntToStr(LineNumber);
Range['A'+LineString,'T'+LineString].Value2:=
VarArrayOf([periodo,dni,qryIncDocMensualname_full.Value,
qryIncDocMensualrama.Value,qryIncDocMensualcod_cargo.Value,hstotal,
qryIncDocMensualPersonal.Value,qryIncDocMensualSitRev.Value,qryIncDocMensualsubv.Value,
qryIncDocMensualAsist.Value,qryIncDocMensualcodigoliquid.Value,qryIncDocMensualclave.Value,
formato(qryIncDocMensualbruto.AsFloat,6),formato(qryIncDocMensualneto.AsFloat,6),
antiguedad,qryIncDocMensualobra_social.Value,qryIncDocMensualsexo.Value,
qryIncDocMensualcuil.Value,qryIncDocMensualcode_denominational.Value,qryIncDocMensualnivel.Value]);
qryIncDocMensual.Next;
end;
Range['A1','T'+ LineString].AutoFormat(xlRangeAutoFormatList1,true,true,false,true,true,true);
Range['A1','T'+ LineString].Columns.AutoFit;
Range['A1','T'+ LineString].HorizontalAlignment := xlcenter;
ActiveWorkbook.SaveAs(filename,null,null,null,false,false,xlnochange,
xlUserResolution,false,null,null,LCID,0);
Quit;
finally
disconnect;
end;// fin del with Range
end;//fin del with ExcelApplication1
end;// fin del if execute
end;//fin del with SaveDialog1
end;//fin del if
 
if radiogroup2.ItemIndex = 0 then
begin
with SaveDialog1 do
begin
FileName := '';
Filter := 'Excel files|*.XLS;All Files|*.*';
DefaultExt := 'xls';
Title := 'Exportando a Excel';
if execute then
begin
qryPrimerSemestre.Open;
LCID := GetUserDefaultLCID;
with ExcelApplication1 do
begin
connect;
try
visible[LCID] := true;
Workbooks.Add(EmptyParam,LCID);
Range['A1','R1'].Value2 := VarArrayOf(['Codigo APS','Mes','Documento','Apellido y Nombre','Rama Enza.','Código del Cargo','Carga Horaria',
'Tipo de Cargo','Sit. Revista','Subvención','Asist.','Clave identif.','Años de Antiguedad','O. social',
'Sexo','Cuil','CUE','Nivel']);
// se definen formatos de las celdas
with Range['A1','R1'] do
begin
HorizontalAlignment := xlcenter;
VerticalAlignment := xlBottom;
Wraptext := false;
orientation := 0;
ShrinkTofit := false;
MergeCells := false;
font.Bold := true;
end;
qryPrimerSemestre.First;
LineNumber := 1;
//envia datos a excel
while not qryPrimerSemestre.Eof do
begin
// horas del cargo
if (qryPrimerSemestreCarga_horaria.IsNull) and (qryPrimerSemestreCarga_C.IsNull) then
hsTotal := 'Nulo' else
begin
if qryPrimerSemestrecarga_horaria.AsInteger <= 0 then
hstotal := qryPrimerSemestrecarga_c.AsString
else
hstotal := qryPrimerSemestrecarga_horaria.AsString;
end;
//DNI
if strtoint(trim(qryPrimerSemestredni.Value)) < 10000000 then
dni := qryPrimerSemestresexodni.Value
else
dni := qryPrimerSemestredni.AsString;
//antiguedad
if qryprimerSemestretotalantig.IsNull then
antiguedad := qryPrimerSemestreAntig.Value
else
antiguedad := qryPrimerSemestretotalAntig.Value;
//RAMA ENZA.
if qryPrimerSemestrerama2.IsNull then
ramaEnza := qryprimerSemestrerama.Value
else
ramaEnza := qryPrimerSemestreRama2.Value;
//Asistencia
if qryPrimerSemestreasist.IsNull then
asist := qryPrimerSemestreasist1.AsInteger
else
asist := qryPrimerSemestreasist.AsInteger;
//mayores a 30
if asist > 30 then
asist := 30;
Inc(LineNumber);
LineString := IntToStr(LineNumber);
Range['A'+LineString,'R'+LineString].Value2:=
VarArrayOf([qryPrimerSemestreenrollment_code.value,qryPrimerSemestreperiod.Value,dni,qryPrimerSemestrename_full.  Value,ramaEnza,
qryPrimerSemestrecod_cargo.Value,hstotal,qryPrimerSemestrepersonal.Value,qryPrimerSemestresitRev.Val  ue,
qryPrimerSemestresubv.Value,asist,qryPrimerSemestreclave.Value,antiguedad,
qryPrimerSemestreobra_social.Value,qryPrimerSemestresexo.Value,qryPrimerSemestreCuil.Value,qryPrimer  Semestrecode_denominational.Value,
qryPrimerSemestrenivel.Value]);
qryPrimerSemestre.Next;
end;
Range['A1','R'+ LineString].AutoFormat(xlRangeAutoFormatList1,true,true,true,true,true,true);
Range['A1','R'+ LineString].Columns.AutoFit;
Range['A1','R'+ LineString].HorizontalAlignment := xlcenter;
ActiveWorkbook.SaveAs(FileName,null,null,null,false,false,xlnochange,
xlUserResolution,false,null,null,LCID,0);
Quit;
finally
disconnect;
end;// fin del with Range
end;//fin del with ExcelApplication1
end;// fin del if execute
end;//fin del with SaveDialog1
end//fin del if radiogroup2
else
begin
with SaveDialog1 do
begin
FileName := '';
Filter := 'Excel files|*.XLS;All Files|*.*';
DefaultExt := 'xls';
Title := 'Exportando a Excel';
if execute then
begin
qrySegundoSemestre.Open;
LCID := GetUserDefaultLCID;
with ExcelApplication1 do
begin
connect;
try
visible[LCID] := true;
Workbooks.Add(EmptyParam,LCID);
Range['A1','R1'].Value2 := VarArrayOf(['Codigo APS','Mes','Documento','Apellido y Nombre','Rama Enza.','Código del Cargo','Carga Horaria',
'Tipo de Cargo','Sit. Revista','Subvención','Asist.','Clave identif.','Años de Antiguedad','O. social',
'Sexo','Cuil','CUE','Nivel']);
// se definen formatos de las celdas
with Range['A1','R1'] do
begin
HorizontalAlignment := xlcenter;
VerticalAlignment := xlBottom;
Wraptext := false;
orientation := 0;
ShrinkTofit := false;
MergeCells := false;
font.Bold := true;
end;
qrySegundoSemestre.First;
LineNumber := 1;
//envia datos a excel
while not qrySegundoSemestre.Eof do
begin
// horas del cargo
if (qrySegundoSemestreCarga_horaria.IsNull) and (qrySegundoSemestreCarga_C.IsNull) then
hsTotal := 'Nulo' else
begin
if qrySegundoSemestrecarga_horaria.AsInteger <= 0 then
hstotal := qryPrimerSemestrecarga_c.AsString
else
hstotal := qrySegundoSemestrecarga_horaria.AsString;
end;
//DNI
if strtoint(trim(qrySegundoSemestredni.Value)) < 10000000 then
dni := qrySegundoSemestresexodni.Value
else
dni := qrySegundoSemestredni.AsString;
//antiguedad
if qryprimerSemestretotalantig.IsNull then
antiguedad := qrySegundoSemestreAntig.Value
else
antiguedad := qrySegundoSemestretotalAntig.Value;
//RAMA ENZA.
if qrySegundoSemestrerama2.IsNull then
ramaEnza := qrySegundoSemestrerama.Value
else
ramaEnza := qrySegundoSemestreRama2.Value;
//Asistencia
if qrySegundoSemestreasist.IsNull then
asist := qrySegundoSemestreasist1.AsInteger
else
asist := qrySegundoSemestreasist.AsInteger;
//mayores a 30
if asist > 30 then
asist := 30;
Inc(LineNumber);
LineString := IntToStr(LineNumber);
Range['A'+LineString,'R'+LineString].Value2:=
VarArrayOf([qrySegundoSemestreenrollment_code.value,qrySegundoSemestreperiod.Value,dni,qrySegundoSemestrename_fu  ll.Value,ramaEnza,
qrySegundoSemestrecod_cargo.Value,hstotal,qrySegundoSemestrepersonal.Value,qrySegundoSemestresitRev.  Value,
qrySegundoSemestresubv.Value,asist,qrySegundoSemestreclave.Value,antiguedad,
qrySegundoSemestreobra_social.Value,qrySegundoSemestresexo.Value,qrySegundoSemestreCuil.Value,qrySeg  undoSemestrecode_denominational.Value,
qrySegundoSemestrenivel.Value]);
qrySegundoSemestre.Next;
end;
Range['A1','R'+ LineString].AutoFormat(xlRangeAutoFormatList1,true,true,true,true,true,true);
Range['A1','R'+ LineString].Columns.AutoFit;
Range['A1','R'+ LineString].HorizontalAlignment := xlcenter;
ActiveWorkbook.SaveAs(FileName,null,null,null,false,false,xlnochange,
xlUserResolution,false,null,null,LCID,0);
Quit;
finally

disconnect;
end;// fin del with Range
end;//fin del with ExcelApplication1
end;// fin del if execute
end;//fin del with SaveDialog1
end;//fin del else
qryIncDocMensual.Close;
qrySegundoSemestre.Close;
qryprimersemestre.Close;
end;

EDITO (Neftalí): Añadidas TAG's Delphi.

Última edición por Neftali [Germán.Estévez] fecha: 15-02-2007 a las 19:33:08.
Responder Con Cita
  #4  
Antiguo 15-02-2007
Avatar de vtdeleon
vtdeleon vtdeleon is offline
Miembro
 
Registrado: abr 2004
Ubicación: RD & USA
Posts: 3.236
Poder: 24
vtdeleon Va por buen camino
Saludos

Bueno...despues de quemarme las pestañas, no he visto la causa por el que te dá ese error de memoria, pero te puedo ayudar a que reduzca considerablemente el codigo, ademas de aconsejarte a que Identes el mismo, porque es dificilisimo leerlo.

Comencemos, veo que hay codigo repetidos, dependiendo del RadioGruop que esté marcado, el cual asigna y query 'X'. Esto lo puedes reducir con la declaracion de una variable (por ejemplo) con la clase Tquery

Declaramos la variable
Código Delphi [-]
var
  DbUso:Tquery;//Un TQuery Por Ejemplo u otra clase Padre
Comenzamos a reducir y reutilizar el codigo
Código Delphi [-]

//Partire de la zona que está en rojo
case radiogroup2.ItemIndex of 
 0: DbUso:=qryPrimerSemestre;
 1: DbUso:=qrySegundoSemestre;
End;
//Asignamos el Query a DbUso, dependiendo del valro de Radiogroup
//entonces cambiamos qrySemestreprincipal y qrySegundosemetre por DbUso

with SaveDialog1 do
begin
 FileName := '';
 Filter := 'Excel files|*.XLS;All Files|*.*';
 DefaultExt := 'xls';
 Title := 'Exportando a Excel';
 if execute then
 begin
  DbUso.Open;
  LCID := GetUserDefaultLCID;
  with ExcelApplication1 do
  begin
   connect;
   try
    visible[LCID] := true;
    Workbooks.Add(EmptyParam,LCID);
    Range['A1','R1'].Value2 := VarArrayOf(['Codigo APS','Mes','Documento','Apellido y Nombre','Rama Enza.','Código del Cargo','Carga Horaria', 'Tipo de Cargo', 'Sit. Revista','Subvención','Asist.','Clave identif.','Años de Antiguedad','O. social',
'Sexo','Cuil','CUE','Nivel']);
    // se definen formatos de las celdas
    with Range['A1','R1'] do
    begin
     HorizontalAlignment := xlcenter;
     VerticalAlignment := xlBottom;
     Wraptext := false;
     orientation := 0;
     ShrinkTofit := false;
     MergeCells := false;
     font.Bold := true;
    end;
    DbUso.First;
    LineNumber := 1;
    //envia datos a excel
    while not DbUso.Eof do
    begin
     // horas del cargo
     if (DbUso.FieldByName('Carga_horaria').IsNull) and (DbUso.FieldByName('Carga_C').IsNull) then
      hsTotal := 'Nulo' else
     begin
      if DbUso.FieldByName('carga_horaria').AsInteger <= 0 then
       hstotal := DbUso.FieldByName('carga_c').AsString
      else
       hstotal := DbUso.FieldByName('carga_horaria').AsString;
     end;
  //DNI
     if strtoint(trim(DbUsodni.Value)) < 10000000 then
      dni := DbUso.FieldByName('sexodni').Value
     else
      dni := DbUso.FieldByName('dni').AsString;
         //antiguedad
     if DbUso.FieldByName('totalantig').IsNull then
      antiguedad := DbUso.FieldByName('Antig').Value
     else
      antiguedad := DbUso.FieldByName('totalAntig').Value;
    //RAMA ENZA.
   if DbUso.FieldByName('rama2').IsNull then
    ramaEnza := DbUso.FieldByName('rama').Value
   else
    ramaEnza := DbUso.FieldByName('Rama2').Value;
    //Asistencia
   if DbUso.FieldByName('asist').IsNull then
    asist := DbUso.FieldByName('asist1').AsInteger
   else
    asist := DbUso.FieldByName('asist').AsInteger;
    //mayores a 30
   if asist > 30 then
    asist := 30;
   Inc(LineNumber);
   LineString := IntToStr(LineNumber);
   Range['A'+LineString,'R'+LineString].Value2:=
   VarArrayOf([DbUso.FieldByName('enrollment_code').value,DbUso.FieldByName('period').Value,dni,   DbUso.FieldByName('name_full').Value, ramaEnza,DbUso.FieldByName('cod_cargo').Value, hstotal,DbUso.FieldByName('personal').Value,DbUso.FieldByName('sitRev').Value, DbUso.FieldByName('subv').Value,asist,DbUso.FieldByName('clave').Value,antiguedad, DbUso.FieldByName('obra_social').Value,DbUso.FieldByName('sexo').Value, DbUso.FieldByName('Cuil').Value,DbUso.FieldByName('Semestrecode_denominational').Value, DbUso.FieldByName('nivel').Value]);
   DbUso.Next;
  end;
    Range['A1','R'+ LineString].AutoFormat(xlRangeAutoFormatList1,true,true,true,true,true,true);
  Range['A1','R'+ LineString].Columns.AutoFit;
  Range['A1','R'+ LineString].HorizontalAlignment := xlcenter;
  ActiveWorkbook.SaveAs(FileName,null,null,null,false,false,xlnochange,
  xlUserResolution,false,null,null,LCID,0);
  Quit;
   finally
  disconnect;
   end;// fin del with Range
  end;//fin del with ExcelApplication1
 end;// fin del if execute
end;
Ya con esto, te has ahorrado la mitad del codigo (La parte azul), DbUso puede contener el 1ro o 2do qry.

Fijate bien, que he realizado algunos cambios , como por ejemplo utilizar FieldbyName(). para asignar valor a los campos.

No soy muy bueno explicando, espero que enteindas. Analizalo un poco

Saludos
__________________
Van Troi De León
(Not) Guía, Code vB:=Delphi-SQL, ¿Cómo?
Viajar en el tiempo no es teóricamente posible, pues si lo fuera, ya estarían aqui contándonos al respecto!

Última edición por vtdeleon fecha: 15-02-2007 a las 23:21:07.
Responder Con Cita
Respuesta



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
Error de Ejecución luxus API de Windows 1 03-11-2006 09:24:13
error en tiempo de ejecución Nelly Varios 9 16-12-2005 15:54:14
error en la ejecucion chechu Varios 5 25-11-2005 00:36:11
Error en tiempo de ejecucion. ramonibk MS SQL Server 2 23-10-2004 20:18:42
Mensaje de error en ejecución andresenlared Conexión con bases de datos 3 08-01-2004 15:14:58


La franja horaria es GMT +2. Ahora son las 06:27:44.


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