Fórum Como fazer uma Thread ??? #158543
07/05/2003
0
Gostaria de saber como eu posso fazer uma thread, peguei o exemplo que vem junto com o delphi e entendi um pouco, gostaria de saber se alguém tem algum exemplo detalhado de como desenvolver uma thread ou alguma apostila ....
Grato
AlphaBlend
Grato
AlphaBlend
Alphablend
Curtir tópico
+ 0
Responder
Posts
07/05/2003
Cfn2003
Da uma olhada no codigo abaixo, meu sistema faz a mesma coisa , so que executa uma sp de mais de 20 M de registros enquanto isto a tela fica atualizando.
O caminho e este, qq estamos ai
Lembrando , o que vc quiser que a thread execute vc deve colocar no thread.EXECUTE
type
TFCalculo = class(TThread)
protected
procedure execute; override;
end;
Type
Mostra = class(tthread)
private
txt : string;
i : integer;
procedure atualizar();
protected
procedure Execute;override;
public
{ Public declarations }
te : boolean;
end;
var
fcalc: Tfcalc;
implementation
uses ffmenu, ffcompras, ffbasedados, ffselecaodata, ffconnect, ffmoving,
ffparalelo,ffconfig,
ffprocess, ffaguardesp;
{$R *.dfm}
{**************************************************************************************************************************
/Inicio das procedures de calculo do sistema}
procedure tfcalc.proces;
begin
with q1 do
begin
active := false;
close;
parameters[0].Value := copy(datetimetostr(DateTimePicker1.Date),1,10);
open;
active := true
end;
end;
procedure tfcalculo.execute();
begin
FreeOnTerminate:=true;
with tadoquery.Create(nil)do
try
connection := fconnect.con;
commandtimeout := 28800;
sql.add(fcalc.strg);
try
fcalc.te := true;
execsql;
except
messagedlg(´Impossível realizar comando! Reinicialize o comando´,mterror,[mbok],0);
end;
finally
free;
fcalc.te := false;
tfcalculo.Create(true);
fcalc.proces;
faguardesp.Close;
end;
exit;
end;
procedure mostra.atualizar();
begin
faguardesp.Label1.Caption := txt;
if faguardesp.Label2.Font.Color = clred then
begin
faguardesp.Label2.Font.Color := clnavy;
end
else if faguardesp.Label2.Font.Color = clnavy then
begin
faguardesp.Label2.Font.Color := clred;
end;
faguardesp.Refresh;
end;
procedure mostra.Execute;
begin
FreeOnTerminate:=true;
faguardesp.BringToFront;
sleep(10);
while fcalc.te = true do
begin
faguardesp.Show;
txt := txt + ´.´;
sleep(500);
Synchronize(Atualizar);
inc(i);
if txt = ´..........´ then
begin
txt := ´´;
end
end;
mostra.Create(true);
exit;
end;
procedure tfcalc.executaSP(strge : string);
begin
strg := strge;
tfcalculo.Create(false);
mostra.Create(false);
end;
O caminho e este, qq estamos ai
Lembrando , o que vc quiser que a thread execute vc deve colocar no thread.EXECUTE
type
TFCalculo = class(TThread)
protected
procedure execute; override;
end;
Type
Mostra = class(tthread)
private
txt : string;
i : integer;
procedure atualizar();
protected
procedure Execute;override;
public
{ Public declarations }
te : boolean;
end;
var
fcalc: Tfcalc;
implementation
uses ffmenu, ffcompras, ffbasedados, ffselecaodata, ffconnect, ffmoving,
ffparalelo,ffconfig,
ffprocess, ffaguardesp;
{$R *.dfm}
{**************************************************************************************************************************
/Inicio das procedures de calculo do sistema}
procedure tfcalc.proces;
begin
with q1 do
begin
active := false;
close;
parameters[0].Value := copy(datetimetostr(DateTimePicker1.Date),1,10);
open;
active := true
end;
end;
procedure tfcalculo.execute();
begin
FreeOnTerminate:=true;
with tadoquery.Create(nil)do
try
connection := fconnect.con;
commandtimeout := 28800;
sql.add(fcalc.strg);
try
fcalc.te := true;
execsql;
except
messagedlg(´Impossível realizar comando! Reinicialize o comando´,mterror,[mbok],0);
end;
finally
free;
fcalc.te := false;
tfcalculo.Create(true);
fcalc.proces;
faguardesp.Close;
end;
exit;
end;
procedure mostra.atualizar();
begin
faguardesp.Label1.Caption := txt;
if faguardesp.Label2.Font.Color = clred then
begin
faguardesp.Label2.Font.Color := clnavy;
end
else if faguardesp.Label2.Font.Color = clnavy then
begin
faguardesp.Label2.Font.Color := clred;
end;
faguardesp.Refresh;
end;
procedure mostra.Execute;
begin
FreeOnTerminate:=true;
faguardesp.BringToFront;
sleep(10);
while fcalc.te = true do
begin
faguardesp.Show;
txt := txt + ´.´;
sleep(500);
Synchronize(Atualizar);
inc(i);
if txt = ´..........´ then
begin
txt := ´´;
end
end;
mostra.Create(true);
exit;
end;
procedure tfcalc.executaSP(strge : string);
begin
strg := strge;
tfcalculo.Create(false);
mostra.Create(false);
end;
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)