PDA

Ver la Versión Completa : Error AccesViolation en Threads


ginasil
10-07-2008, 23:03:23
Hola a todos,
Por favor me podrian colaborar con u problema con Threads que generan error Accesviolation, segun lo que lei un thread "All threads of a process share the same address space" y no he podido hacer que cada uno tenga una dirección diferente.
tengo 10 progressBar y 10 checklistbox donde la idea es que por cada checklist un Thread me indique en el progressbar que el checklist esta actualizado:

type
Thilo_muestraestado = class(TThread)
private
Caja: TCheckListBox;
Num,mensaje,cod,accion,tipo : String;
protected
procedure Execute; override;
procedure MostrarProgreso;
procedure MostrarProgreso2;
public
constructor Create(Caja: TCheckListBox;Num : string);
end;

/**en public
hilo1,hilo2,..... hasta hilo10 : Thilo_muestraestado;

procedure Thilo_muestraestado.Execute;
var
k,i : integer;
begin
try
while not Terminated do
begin
//*** Ejecuta una consulta y si la hace
Synchronize( MostrarProgreso );
y si no la hace...
Synchronize( MostrarProgreso2 );
end;
finally
end;
end;

//** cuando inicia el form asigno los diez hilos...
if not Assigned(hilo0) then hilo0 := Thilo_muestraestado.Create(StringGrid2,'0');
if not Assigned(hilo1) then hilo1 := Thilo_muestraestado.Create(StringGrid3,'1');
... y asi...

procedure Thilo_muestraestado.MostrarProgreso;
begin
if Terminated then exit;
... agrega y borra lineas del stringrid... que lo llamo

if cajon = '0' then aumenta(Form1.ProgressBar0);
if cajon = '1' then aumenta(Form1.ProgressBar1);
y asi los diez...
end;

procedure Thilo_muestraestado.MostrarProgreso2;
begin
/**solo para que muestre progreso....
if cajon = '0' then aumenta(Form1.ProgressBar0);
if cajon = '1' then aumenta(Form1.ProgressBar1);
y asi los diez...
end;

Gracias

coso
10-07-2008, 23:18:09
Hola. Se supone que en el constructor creas el checkbox no? veo q tienes el nombre del parametro (caja) igual que el de la variable. Me parece que el problema esta por alli...

EDITO : relei y quizas no. mediante el debugger, en que linea se te para?

ginasil
10-07-2008, 23:40:43
se para en: while not Terminated do y saca 4 errores y no vuelven a funcional los hilos...

los checklistbox los tengo en el form para que me muestre una serie de datos...

gracias

coso
10-07-2008, 23:47:14
pero ... exactamente en la linea while not terminated? f7,f8 con project->options->compiler->debug options activadas.

ginasil
11-07-2008, 14:08:32
con F7 justo en ese punto sale Internal Error y se queda ahi..

ginasil
11-07-2008, 14:18:55
dentro del execute yo he colocado un Tquery
var
consulta : TQuery;

y lleno esa consulta y es alli donde manda el AccessViolation
consulta.SQL.Clear;
consulta.SQL.Add(' select codigo from rutas ');
consulta.SQL.Add(' where estado <> '+cajon + ' ' + ' and codigo in (' +rutas+ ')' );
consulta.Active := true;
consulta.First;

y cuando miro el debug threads muestra un thread id por cada hilo pero todos en la misma location (direccion de memoria?)...

gracias

coso
11-07-2008, 14:52:12
entonces es en la linea anterior del while not Terminated. Dicho de otra manera, el error no te lo crea el while not Terminated. Si fuese asi, significaria que todo el objeto THilo no esta creado. El query que mencionabas antes... lo creas correctamente, esta correctamente conectado y lo liberas despues de usarlo? creo que a estas alturas si pusieras el codigo entero (o adjuntado) del metodo donde te salta la excepcion...

PD : rutas es el nombre de la tabla, y tambien el de la variable?

ginasil
11-07-2008, 19:36:53
si, rutas es el nombre de la tabla y un string que me trae las rutas que voy a buscar en la tabla rutas...

cuando con F7 sale del procedimiento no desaparece el hilo en memoria.. sigue con la misma dirección... y como he creado 10 hilos del mismo tipo hilo.. aparecen los 10 con el mimo numero en memoria... y cuando intenta volver sobre el primer hilo ahi es cuando sale el error...

coso
11-07-2008, 19:44:00
entonces...cuando se termina el hilo, lo destruyes, y no lo vuelves a crear aunque si lo vuelves a llamar...es eso?

ginasil
14-07-2008, 14:10:55
Gracias por tu ayuda...

no he entendido muy bien lo de los hilos... esos hilos deben destruirse o deben quedar alli latentes... la idea final es que se actualicen constantemente las casillas (cajones o stringridbox) con las rutas... y no le tengo nada que los destruya... no he podido entender si es que no puedo definir tantos hilos del mismo tipo o si falta algo para que cuando intenta utilizar el hilo definido no marque el error... o si es que no se hace asi...

ginasil
14-07-2008, 14:13:40
perdon son checklistbox con las rutas... y progressbar para ver que lo esta haciendo constantemente...

coso
14-07-2008, 17:22:16
ok pero estaria bien que me contestaras algunas de las preguntas que te he hecho, porque sino, seguimos estando igual :

- creas (metodo create) correctamente el hilo? prueba de poner antes del primer try en .execute : if (self) = nil then Showmessage('no asignado') a ver si te salta este mensaje
- creas y destruyes correctamente el query?
- es posible que una vez terminado el hilo, lo destruyas y luego lo vuelvas a llamar sin haberlo recreado?

tal como te dije, a estas alturas si pusieras el codigo entero (o adjuntado) del metodo donde te salta la excepcion... y del .create tambien. venga saludos y suerte

coso
14-07-2008, 17:23:52
y hilo1, hilo2, etc... los creas? haces hilo1 := Thilomuestra_Estado.create(checkbox1,1)?

ginasil
15-07-2008, 20:23:38
oye gracias...es un codigo al que le hago mantenimiento y no cabe...... revise como me dijiste y separé el código de los hilos .......

parte i

unit Unit6;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls,inifiles, ExtCtrls, CheckLst,QDialogs,
Buttons,math, Grids, DBGrids, Psock, NMFtp, Menus, Mask, FileCtrl, SBSftpCommon,
SBSimpleSftp, SBX509, SBCustomCertStorage, SBPGPKeys,SBSSHKeyStorage,SBSSHConstants,
SBUtils,DateUtils,registry,db,dbtables;
const SFTP_BLOCK_SIZE = $10000;
type Tordenesdias = array[1..7] of string;
type
Thilo_mostrandoestados = class(TThread)
private
FBox: TCheckListBox;
Fcajon,mensaje,codruta,accion,tipo_de_sinc : String;
// estadocomparando : integer;
protected
procedure Execute; override;
procedure MostrarProgreso;
procedure MostrarProgreso2;
public
constructor Create(Box: TCheckListBox;cajon : string);
// destructor Destroy; override;
end;
type
Thilo_mostrandoestados2 = class(TThread)
private
FBox: TStringGrid;
Fcajon,mensaje,codruta,accion,tipo_de_sinc : String;
estadocomparando : integer;
protected
procedure Execute; override;
procedure MostrarProgreso;
procedure MostrarProgreso2;
public
constructor Create(Box: TStringGrid;cajon : string);
end;

type
TForm6 = class(TForm)
PageControl1: TPageControl;
TabSheet1: TTabSheet;
StringGrid3: TStringGrid;
StringGrid2: TStringGrid;
CheckListBox2: TCheckListBox;
CheckListBox6: TCheckListBox;
CheckListBox3: TCheckListBox;
CheckListBox5: TCheckListBox;
CheckListBox4: TCheckListBox;
CheckListBox7: TCheckListBox;
CheckListBox1: TCheckListBox;
SpeedButton28: TSpeedButton;
ProgressBar10: TProgressBar;
ProgressBar7: TProgressBar;
ProgressBar6: TProgressBar;
ProgressBar8: TProgressBar;
ProgressBar9: TProgressBar;
ProgressBar5: TProgressBar;
ProgressBar4: TProgressBar;
ProgressBar1: TProgressBar;
StringGrid5: TStringGrid;
Memomostrarhilo: TMemo;
BitBtn1: TBitBtn;
procedure FormActivate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure SpeedButton28Click(Sender: TObject);
procedure listarrutas;
procedure insertarpaso(ruta,paso,tipoproceso,agentes : string);
function rutas_en_cajones(posiciones : Tstrings): string;
function aumentar(barra : TProgressBar) : boolean;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
hilo0 : Thilo_mostrandoestados2;
hilo1,hilo2,hilo3,hilo4,hilo5,hilo6,hilo9 : Thilo_mostrandoestados;
{ Public declarations }
end;
var
Form6: TForm6;
implementation
uses Unit2, Unit3;
{$R *.dfm}
procedure TForm6.FormActivate(Sender: TObject);
begin
hilo0.Resume;
hilo1.Resume;
hilo2.Resume;
hilo3.Resume;
hilo4.Resume;
hilo5.Resume;
hilo6.Resume;
hilo9.Resume;
end;
procedure TForm6.FormShow(Sender: TObject);
begin
StringGrid3.Cells[0,0] := 'Ruta';
StringGrid3.Cells[1,0] := 'P';
StringGrid3.Cells[2,0] := 'A';
StringGrid3.Cells[3,0] := 'E';
end;
procedure TForm6.SpeedButton28Click(Sender: TObject);
begin
listarrutas;
hilo0.Resume;
hilo1.Resume;
hilo2.Resume;
hilo3.Resume;
hilo4.Resume;
hilo5.Resume;
hilo6.Resume;
hilo9.Resume;
end;

procedure TForm6.listarrutas;
var
i,j,verificador : integer;
primero : boolean;
begin
dt.qbusca.Active := false;
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add('select count(*) as contador from sincronizadas ');
dt.qbusca.Active := true;
dt.qbusca.First;
verificador := dt.qbusca.FieldByName('contador').AsInteger;
if verificador = 0 then
begin
// inicia de ceros
for i := 0 to StringGrid2.RowCount - 1 do
begin
for j := 0 to StringGrid2.ColCount - 1 do
begin
StringGrid2.Cells[j,i] := '';
end;
end;
dt.qbusca.Active := false;
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add('select codigo from ruta where tienehh = "s" and activo = "1" and modem = "n" order by codigo ');
try
dt.qbusca.Active := true;
except
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add('select codigo from ruta where tienehh = "s" and activo = "1" order by codigo ');
dt.qbusca.Active := true;
end;
dt.qbusca.First;
StringGrid2.RowCount := dt.qbusca.RecordCount;
for i := 0 to dt.qbusca.RecordCount - 1 do
begin
StringGrid2.Cells[0,i] := dt.qbusca.fieldbyname('codigo').AsString;
StringGrid2.Cells[1,i] := '';
insertarpaso(dt.qbusca.fieldbyname('codigo').AsString,'0','-','-');
dt.qbusca.Next;
end;
StringGrid2.Enabled := true;
//creartablashh;
end //no es nuevo
else
begin
//
dt.qbusca.Active := false;
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add(' select * from sincronizadas ');
dt.qbusca.Active := true;
dt.qbusca.First;
StringGrid2.RowCount := 0;
primero := true;

CheckListBox1.Items.Clear;
CheckListBox2.Items.Clear;
CheckListBox3.Items.Clear;
CheckListBox4.Items.Clear;
CheckListBox5.Items.Clear;
CheckListBox6.Items.Clear;
CheckListBox7.Items.Clear;
// CheckListBox10.Items.Clear;
// CheckListBox11.Items.Clear;
for i := 0 to StringGrid2.RowCount - 1 do
begin
for j := 0 to StringGrid2.ColCount - 1 do
begin
StringGrid2.Cells[j,i] := '';
end;
end;
for i := 0 to StringGrid5.RowCount - 1 do
begin
for j := 0 to StringGrid5.ColCount - 1 do
begin
StringGrid5.Cells[j,i] := '';
end;
end;
StringGrid5.RowCount := dt.qbusca.RecordCount;

for i := 0 to dt.qbusca.RecordCount - 1 do
begin
StringGrid5.Cells[0,i] := dt.qbusca.FieldByName('codruta').AsString;
StringGrid5.Cells[1,i] := dt.qbusca.FieldByName('tipo_de_sinc').AsString;
if dt.qbusca.FieldByName('estado').AsInteger = 0 then
begin
if primero then
begin
StringGrid2.Cells[0,StringGrid2.RowCount - 1] := dt.qbusca.FieldByName('codruta').AsString;
StringGrid2.Cells[1,StringGrid2.RowCount - 1] := '';
primero := false;
end
else
begin
StringGrid2.RowCount := StringGrid2.RowCount + 1;
StringGrid2.Cells[0,StringGrid2.RowCount - 1] := dt.qbusca.FieldByName('codruta').AsString;
StringGrid2.Cells[1,StringGrid2.RowCount - 1] := '';
end;

end
else if dt.qbusca.FieldByName('estado').AsInteger = 1 then
begin
CheckListBox2.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 2 then
begin
CheckListBox6.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 3 then
begin
CheckListBox3.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 4 then
begin
CheckListBox5.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 5 then
begin
CheckListBox4.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 6 then
begin
CheckListBox7.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end
else if dt.qbusca.FieldByName('estado').AsInteger = 7 then
begin
CheckListBox1.Items.Add(dt.qbusca.FieldByName('codruta').AsString);
end;

dt.qbusca.Next;
end;

end;
dt.qbusca.Active := false;
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add(' select count(r.codigo) as contador from ruta r left join sincronizadas s on r.codigo = s.codruta ');
dt.qbusca.SQL.Add(' where s.codruta is null and r.tienehh = "s" and r.modem = "n" ');
try
dt.qbusca.Active := true;
except
dt.qbusca.SQL.Clear;
dt.qbusca.SQL.Add(' select count(r.codigo) as contador from ruta r left join sincronizadas s on r.codigo = s.codruta ');
dt.qbusca.SQL.Add(' where s.codruta is null and r.tienehh = "s" ');
dt.qbusca.Active := true;
end;
dt.qbusca.First;
verificador := dt.qbusca.FieldByName('contador').AsInteger;
if verificador > 0 then
begin
// showmessage('13');
dt.qins.Active := false;
dt.qins.SQL.Clear;
dt.qins.SQL.Add(' insert into sincronizadas ');
dt.qins.SQL.Add(' select r.codigo,"0","-","-" from ruta r left join sincronizadas s on r.codigo = s.codruta ');
dt.qins.SQL.Add(' where s.codruta is null and r.tienehh = "s" and r.modem = "n" ');
try
dt.qins.ExecSQL;
except
dt.qins.SQL.Add(' insert into sincronizadas ');
dt.qins.SQL.Add(' select r.codigo,"0","-","-" from ruta r left join sincronizadas s on r.codigo = s.codruta ');
dt.qins.SQL.Add(' where s.codruta is null and r.tienehh = "s" ');
dt.qins.ExecSQL;
end;


ShowMessage('ESTA APLICACION HA DETECTADO RUTAS NUEVAS, SE CERRARA... INGRESE NUEVAMENTE..');
Application.Terminate;
end;
if not Assigned(hilo0) then hilo0 := Thilo_mostrandoestados2.Create(StringGrid2,'0');
if not Assigned(hilo1) then hilo1 := Thilo_mostrandoestados.Create(CheckListBox2,'1');
if not Assigned(hilo2) then hilo2 := Thilo_mostrandoestados.Create(CheckListBox6,'2');
if not Assigned(hilo3) then hilo3 := Thilo_mostrandoestados.Create(CheckListBox3,'3');
if not Assigned(hilo4) then hilo4 := Thilo_mostrandoestados.Create(CheckListBox5,'4');
if not Assigned(hilo5) then hilo5 := Thilo_mostrandoestados.Create(CheckListBox4,'5');
if not Assigned(hilo6) then hilo6 := Thilo_mostrandoestados.Create(CheckListBox7,'6');
if not Assigned(hilo9) then hilo9 := Thilo_mostrandoestados.Create(CheckListBox1,'7');
end;

ginasil
15-07-2008, 20:24:25
parte ii

constructor Thilo_mostrandoestados.Create(Box: TCheckListBox;cajon : string);
begin
FBox := Box;
FCajon := cajon;
// FreeOnTerminate := True;
inherited Create(true);
Priority := tpHigher; // tpNormal;
end;
constructor Thilo_mostrandoestados2.Create(Box: TStringGrid ;cajon : string);
begin
FBox := Box;
FCajon := cajon;
// FreeOnTerminate := True;
inherited Create(true);
Priority := tpHigher;
end;

procedure Thilo_mostrandoestados.Execute;
var
consulta : TQuery;
// basededatos_1 : TDatabase;
// session_1 : TSession;
rutas,consulta2: string;
k,i : integer;
begin
if (self) = nil then Showmessage('no asignado');
try
while not Terminated do
begin
consulta := TQuery.create(Application);
consulta.Active := false;
consulta.DatabaseName := 'inase';
rutas := Form6.rutas_en_cajones(FBox.Items);
if rutas <> '' then
begin
consulta2 := ' and codruta in (' +rutas+ ')';
end
else
begin
consulta2 := '';
end;
if consulta2 <> '' then
begin
consulta.SQL.Clear;
consulta.SQL.Add(' select codruta,tipo_de_sinc from sincronizadas ');
consulta.SQL.Add(' where estado <> '+Fcajon + ' ' + consulta2 );
consulta.Active := true;
consulta.First;
for k := 0 to consulta.RecordCount - 1 do
begin
accion := 'borrar';
codruta := consulta.FieldByName('codruta').AsString;
tipo_de_sinc := consulta.FieldByName('tipo_de_sinc').AsString;
Synchronize( MostrarProgreso );
Sleep(100);
consulta.Next;
end;
end;

if rutas <> '' then
begin
consulta2 := ' and codruta not in (' +rutas+ ')';
end
else
begin
consulta2 := '';
end;

consulta.SQL.Clear;
consulta.SQL.Add(' select codruta,tipo_de_sinc from sincronizadas ');
consulta.SQL.Add(' where estado = '+Fcajon + ' ' + consulta2 );
consulta.Active := true;
consulta.First;
for k := 0 to consulta.RecordCount - 1 do
begin
if FBox.Items.IndexOf(consulta.FieldByName('codruta').AsString) = -1 then
begin
accion := 'agregar';
codruta := consulta.FieldByName('codruta').AsString;
tipo_de_sinc := consulta.FieldByName('tipo_de_sinc').AsString;
Sleep(50);
Synchronize( MostrarProgreso );

end;
consulta.Next;
end;

consulta.Close;
consulta.Destroy;
Synchronize( MostrarProgreso2 );
Sleep(300);
end;
finally
// consulta.Destroy;
// FBox.Free;
// Form6.RichEdit1.Lines.Add(' se cerro el hilo del cajon = ' + Fcajon);
end;
end;
procedure Thilo_mostrandoestados2.Execute;
var
consulta : TQuery;
rutas,consulta2: string;
k,l,posicion : integer;
begin
if (self) = nil then Showmessage('no asignado');
try
while not Terminated do
begin
consulta := TQuery.create(Application);
consulta.Active := false;
consulta.DatabaseName := 'inase';
rutas := Form6.rutas_en_cajones(FBox.Cols[0]);
if (rutas <> ',') or (rutas <> '') then
begin
consulta2 := ' and codruta in (' +rutas+ ')';
end
else
begin
consulta2 := '';
end;
if consulta2 = ' and codruta in ()' then
begin
consulta2 := '';
end;
consulta.SQL.Clear;
consulta.SQL.Add(' select codruta,tipo_de_sinc from sincronizadas ');
consulta.SQL.Add(' where estado <> ' + Fcajon + ' ' + consulta2 );
consulta.Active := true;
consulta.First;
for k := 0 to consulta.RecordCount - 1 do
begin
accion := 'borrar';
codruta := consulta.FieldByName('codruta').AsString;
tipo_de_sinc := consulta.FieldByName('tipo_de_sinc').AsString;
Synchronize( MostrarProgreso );
Sleep(50);
consulta.Next;
end;
if rutas <> '' then
begin
consulta2 := ' and codruta not in (' +rutas+ ')';
end
else
begin
consulta2 := '';
end;
consulta.SQL.Clear;
consulta.SQL.Add(' select codruta,tipo_de_sinc from sincronizadas ');
consulta.SQL.Add(' where estado = '+Fcajon + ' ' + consulta2 );
consulta.Active := true;
consulta.First;
for k := 0 to consulta.RecordCount - 1 do
begin
if FBox.Cells[0,FBox.RowCount - 1] <> '' then
begin
accion := 'agregar';
codruta := consulta.FieldByName('codruta').AsString;
tipo_de_sinc := consulta.FieldByName('tipo_de_sinc').AsString;
Synchronize( MostrarProgreso );
Sleep(50);
end;
consulta.Next;
end;

consulta.Close;
consulta.Destroy;
Synchronize( MostrarProgreso2 );
Sleep(400);
end;

finally
end;
end;

procedure Thilo_mostrandoestados.MostrarProgreso;
begin
if Terminated then exit;
if mensaje <> '' then
begin
Form6.Memomostrarhilo.Lines.Add(mensaje + ' <=> ' + FormatDateTime('hh:nn:ss',now));
end;
if accion = 'borrar' then
begin
FBox.Items.Delete(FBox.items.Indexof(codruta));
end;
if accion = 'agregar' then
begin
FBox.Items.Add(codruta);
end;
if Form6.StringGrid5.Cols[0].IndexOf(codruta) >= 0 then
begin
Form6.StringGrid5.Cells[1,Form6.StringGrid5.Cols[0].IndexOf(codruta)] := tipo_de_sinc;
end
else
begin
Form6.StringGrid5.RowCount := Form6.StringGrid5.RowCount + 1;
Form6.StringGrid5.Cells[0,Form6.StringGrid5.RowCount - 1] := codruta;
Form6.StringGrid5.Cells[1,Form6.StringGrid5.RowCount - 1] := tipo_de_sinc;
end;

// FBox.Repaint;
if Fcajon = '1' then Form6.aumentar(Form6.ProgressBar10);
if Fcajon = '2' then Form6.aumentar(Form6.ProgressBar9);
if Fcajon = '3' then Form6.aumentar(Form6.ProgressBar8);
if Fcajon = '4' then Form6.aumentar(Form6.ProgressBar7);
if Fcajon = '5' then Form6.aumentar(Form6.ProgressBar6);
if Fcajon = '6' then Form6.aumentar(Form6.ProgressBar5);
if Fcajon = '7' then Form6.aumentar(Form6.ProgressBar4);

end;
procedure Thilo_mostrandoestados.MostrarProgreso2;
begin
if Terminated then exit;
if mensaje <> '' then
begin
Form6.Memomostrarhilo.Lines.Add(mensaje + ' <=> ' + FormatDateTime('hh:nn:ss',now));
end;
// FBox.Repaint;
if Fcajon = '1' then Form6.aumentar(Form6.ProgressBar10);
if Fcajon = '2' then Form6.aumentar(Form6.ProgressBar9);
if Fcajon = '3' then Form6.aumentar(Form6.ProgressBar8);
if Fcajon = '4' then Form6.aumentar(Form6.ProgressBar7);
if Fcajon = '5' then Form6.aumentar(Form6.ProgressBar6);
if Fcajon = '6' then Form6.aumentar(Form6.ProgressBar5);
if Fcajon = '7' then Form6.aumentar(Form6.ProgressBar4);

end;

procedure Thilo_mostrandoestados2.MostrarProgreso;
var
posicion,l : integer;
begin
if Terminated then exit;
if mensaje <> '' then
begin
Form6.Memomostrarhilo.Lines.Add(mensaje + ' <=> ' + FormatDateTime('hh:nn:ss',now));
end;
if accion = 'borrar' then
begin
posicion := FBox.Cols[0].IndexOf(codruta);
for l := posicion to Form6.StringGrid2.RowCount - 1 do
begin
Form6.StringGrid2.Cells[0,l] := Form6.StringGrid2.Cells[0,l + 1];
Form6.StringGrid2.Cells[1,l] := Form6.StringGrid2.Cells[1,l + 1];
Form6.StringGrid2.Cells[2,l] := Form6.StringGrid2.Cells[2,l + 1];
Form6.StringGrid2.Cells[3,l] := Form6.StringGrid2.Cells[2,l + 1];
end;
Form6.StringGrid2.RowCount := Form6.StringGrid2.RowCount - 1;
end;
if accion = 'agregar' then
begin
Form6.StringGrid2.RowCount := FBox.RowCount + 1;
Form6.StringGrid2.Cells[0,Form6.StringGrid2.RowCount - 1] := codruta;
Form6.StringGrid2.Cells[1,Form6.StringGrid2.RowCount - 1] := '';
Form6.StringGrid2.Cells[2,Form6.StringGrid2.RowCount - 1] := '';
Form6.StringGrid2.Cells[3,Form6.StringGrid2.RowCount - 1] := '';
end;


if Form6.StringGrid5.Cols[0].IndexOf(codruta) >= 0 then
begin
Form6.StringGrid5.Cells[1,Form6.StringGrid5.Cols[0].IndexOf(codruta)] := tipo_de_sinc;
end
else
begin
Form6.StringGrid5.RowCount := Form6.StringGrid5.RowCount + 1;
Form6.StringGrid5.Cells[0,Form6.StringGrid5.RowCount - 1] := codruta;
Form6.StringGrid5.Cells[1,Form6.StringGrid5.RowCount - 1] := tipo_de_sinc;
end;
// FBox.Repaint;
if Form6.ProgressBar1.Position = 499 then
begin
Form6.ProgressBar1.Position := 0;
end;
Form6.ProgressBar1.Position := Form6.ProgressBar1.Position + 1;
end;
procedure Thilo_mostrandoestados2.MostrarProgreso2;
var
posicion,l : integer;
begin
if Terminated then exit;
if mensaje <> '' then
begin
Form6.Memomostrarhilo.Lines.Add(mensaje + ' <=> ' + FormatDateTime('hh:nn:ss',now));
end;

// FBox.Repaint;
if Form6.ProgressBar1.Position = 499 then
begin
Form6.ProgressBar1.Position := 0;
end;
Form6.ProgressBar1.Position := Form6.ProgressBar1.Position + 1;
end;
procedure TForm6.insertarpaso(ruta,paso,tipoproceso,agentes : string);
var
id_log_ipegasohh_move : string;
begin
dt.Qrf.Active := false;
dt.Qrf.SQL.Clear;
dt.Qrf.SQL.Add(' replace into sincronizadas values ("' +ruta+ '","' +paso+ '","' +tipoproceso+ '","' +agentes+ '")');
dt.Qrf.ExecSQL;
if StringGrid5.Cols[0].IndexOf(ruta) >= 0 then
begin
StringGrid5.Cells[1,StringGrid5.Cols[0].IndexOf(ruta)] := tipoproceso;
end
else
begin
StringGrid5.RowCount := StringGrid5.RowCount + 1;
StringGrid5.Cells[0,StringGrid5.RowCount - 1] := ruta;
StringGrid5.Cells[1,StringGrid5.RowCount - 1] := tipoproceso;
end;

dt.Qrf.Active := false;
dt.Qrf.SQL.Clear;
dt.Qrf.SQL.Add(' insert into log_ipegasohh_move_movimientos_2 (usuario,comentario,codruta,fecha,transmision,estado,proceso) values ( ');
dt.Qrf.SQL.Add('"' +Form3.Edit1.Text +'",');
dt.Qrf.SQL.Add('"N/A",');
dt.Qrf.SQL.Add('"' +ruta+ '",');
dt.Qrf.SQL.Add('"' +FormatDateTime('yyyy-mm-dd hh:nn:ss',now)+ '", ');
dt.Qrf.SQL.Add('"N",');
dt.Qrf.SQL.Add('"' +paso+ '",');
dt.Qrf.SQL.Add('"' +tipoproceso+ '")');
dt.Qrf.ExecSQL
end;
function TForm6.rutas_en_cajones(posiciones : TStrings): string;
var
i : integer;
resultado : string;
begin
resultado := '';
for i := 0 to posiciones.Count - 1 do
begin
resultado :=resultado + posiciones.Strings[i] + ',';
end;
resultado := Copy(resultado,0,length(resultado) - 1);
result := resultado;
end;
function TForm6.aumentar(barra : TProgressBar) : boolean;
begin
if barra.Position = 499 then
begin
barra.Position := 0;
end;
barra.Position := barra.Position + 1;
end;
procedure TForm6.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if hilo0 <> nil then
begin
hilo0.Terminate;
hilo0.WaitFor;
hilo0.Free;
hilo0 := nil;
end;
if hilo1 <> nil then
begin
hilo1.Terminate;
hilo1.WaitFor;
hilo1.Free;
hilo1 := nil;
end;
if hilo2 <> nil then
begin
hilo2.Terminate;
hilo2.WaitFor;
hilo2.Free;
hilo2 := nil;
end;
if hilo3 <> nil then
begin
hilo3.Terminate;
hilo3.WaitFor;
hilo3.Free;
hilo3 := nil;
end;
if hilo4 <> nil then
begin
hilo4.Terminate;
hilo4.WaitFor;
hilo4.Free;
hilo4 := nil;
end;
if hilo5 <> nil then
begin
hilo5.Terminate;
hilo5.WaitFor;
hilo5.Free;
hilo5 := nil;
end;
if hilo6 <> nil then
begin
hilo6.Terminate;
hilo6.WaitFor;
hilo6.Free;
hilo6 := nil;
end;
if hilo9 <> nil then
begin
hilo9.Terminate;
hilo9.WaitFor;
hilo9.Free;
hilo9 := nil;
end;
Sleep(1000);
end;
procedure TForm6.BitBtn1Click(Sender: TObject);
begin
listarrutas;
PageControl1.ActivePageIndex := 0;
end;
end.

coso
15-07-2008, 21:09:56
te salto el mensaje de no asignado?

ginasil
18-07-2008, 17:27:37
oye gracias... lo estaba volviendo a crear desde otro punto :)