B
bxp780921
Unregistered / Unconfirmed
GUEST, unregistred user!
我使用synchronize调用了一个线程中的过程后,主界面就什么也不能做,我想在他工作的过程中自少有一个按狃能终止他现成执行,现在只好等他自己执行完,
我创建线程是 aa:=zkthread.Create(false);
我的线程是
unit zk;
interface
uses
Fmakecard_msgDAO01,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,xtqq;
type
zkthread = class(TThread)
private
Fmakecard_msgDAO01:TFmakecard_msgDAO01;
{ Private declarations }
protected
procedure Execute;
override;
public
procedure zk;
end;
implementation
uses makecard_msg, makecard;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure zkthread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ zkthread }
procedure zkthread.Execute;
begin
try
synchronize(zk);
//线程同步
except
Terminate ;
showmessage('线程同步错误');
end;
end;
procedure zkthread.zk;
var
Vaac001,Vaac003,Vaac004,vack020,Vsac100:string;
vFErrCode:string;
a,b,c:integer;
begin
a:=0;
b:=0;
Fmakecard_msg.ProgressBar1.Min :=0;
Fmakecard_msg.ProgressBar1.Max :=Fmakecard_msg.ADS_a.RecordCount;
Fmakecard_msg.ProgressBar1.Position:=0;
Fmakecard_msg.ADS_a.First ;
FreeOnTerminate :=True;
while not Fmakecard_msg.ADS_a.Eofdo
begin
//判断终止标志
if Vzkzdbz=True then
begin
//开始中间层提交
Vaac001:=Fmakecard_msg.ADS_a.FieldByName('AAC001').AsString;
//个人序号
Vaac003:=Fmakecard_msg.ADS_a.FieldByName('aac003').AsString ;
//姓名
//转换性别1为男2为女
if trim(Fmakecard_msg.ADS_a.FieldByName('aac004').AsString)='1' then
begin
Vaac004:='男';
//姓别
end
else
if trim(Fmakecard_msg.ADS_a.FieldByName('aac004').AsString)='2' then
begin
Vaac004:='女';
//姓别
end;
//向服务器发出数据请求
try
Fmakecard_msgDAO01:=TFmakecard_msgDAO01.Create(Nil);
Fmakecard_msgDAO01.Load;
try
with Fmakecard_msgDAO01.Inkc06do
begin
Append;
FieldByName('aac001').AsString :=vaac001;
Post;
end;
except
on E: Exceptiondo
end;
Fmakecard_msgDAO01.SendRequest;
vFErrCode:=Fmakecard_msgDAO01.ErrCode;
if Fmakecard_msgDAO01.Outkc06.RecordCount>0 then
begin
vack020:=Fmakecard_msgDAO01.Outkc06.FieldByName('akc020').AsString ;
end
else
begin
vack020:='没有返回卡号';
end;
finally
FreeAndNil(Fmakecard_msgDAO01);
end;
//判断返回信息,如果OK制卡成功,否制卡失败
if uppercase(Trim(vFErrCode))='OK' then
begin
a:=a+1;
Fmakecard_msg.Label2.Caption :='成功:'+inttostr(a);
//个人编号和卡号储存起来,退出时更新主界面中的信息
vsac100stringList.Add(VAAC001);
vakc020stringList.Add(vack020);
end
else
begin
b:=b+1;
Fmakecard_msg.memo1.Lines.Add('个人序号:'+Vaac001+':'+'姓名:'+ Vaac003 +':'+ Vaac004 +':'+vFErrCode+#13) ;
Fmakecard_msg.Label3.Caption :='失败:'+inttostr(b);
end;
//进度条增加
Fmakecard_msg.ProgressBar1.Position:=Fmakecard_msg.ProgressBar1.Position+1;
Fmakecard_msg.ADS_a.Next;
end;
end;
//关闭按牛打开
Fmakecard_msg.Button1.Enabled :=True;
end;
end.
我创建线程是 aa:=zkthread.Create(false);
我的线程是
unit zk;
interface
uses
Fmakecard_msgDAO01,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,xtqq;
type
zkthread = class(TThread)
private
Fmakecard_msgDAO01:TFmakecard_msgDAO01;
{ Private declarations }
protected
procedure Execute;
override;
public
procedure zk;
end;
implementation
uses makecard_msg, makecard;
{ Important: Methods and properties of objects in visual components can only be
used in a method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure zkthread.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ zkthread }
procedure zkthread.Execute;
begin
try
synchronize(zk);
//线程同步
except
Terminate ;
showmessage('线程同步错误');
end;
end;
procedure zkthread.zk;
var
Vaac001,Vaac003,Vaac004,vack020,Vsac100:string;
vFErrCode:string;
a,b,c:integer;
begin
a:=0;
b:=0;
Fmakecard_msg.ProgressBar1.Min :=0;
Fmakecard_msg.ProgressBar1.Max :=Fmakecard_msg.ADS_a.RecordCount;
Fmakecard_msg.ProgressBar1.Position:=0;
Fmakecard_msg.ADS_a.First ;
FreeOnTerminate :=True;
while not Fmakecard_msg.ADS_a.Eofdo
begin
//判断终止标志
if Vzkzdbz=True then
begin
//开始中间层提交
Vaac001:=Fmakecard_msg.ADS_a.FieldByName('AAC001').AsString;
//个人序号
Vaac003:=Fmakecard_msg.ADS_a.FieldByName('aac003').AsString ;
//姓名
//转换性别1为男2为女
if trim(Fmakecard_msg.ADS_a.FieldByName('aac004').AsString)='1' then
begin
Vaac004:='男';
//姓别
end
else
if trim(Fmakecard_msg.ADS_a.FieldByName('aac004').AsString)='2' then
begin
Vaac004:='女';
//姓别
end;
//向服务器发出数据请求
try
Fmakecard_msgDAO01:=TFmakecard_msgDAO01.Create(Nil);
Fmakecard_msgDAO01.Load;
try
with Fmakecard_msgDAO01.Inkc06do
begin
Append;
FieldByName('aac001').AsString :=vaac001;
Post;
end;
except
on E: Exceptiondo
end;
Fmakecard_msgDAO01.SendRequest;
vFErrCode:=Fmakecard_msgDAO01.ErrCode;
if Fmakecard_msgDAO01.Outkc06.RecordCount>0 then
begin
vack020:=Fmakecard_msgDAO01.Outkc06.FieldByName('akc020').AsString ;
end
else
begin
vack020:='没有返回卡号';
end;
finally
FreeAndNil(Fmakecard_msgDAO01);
end;
//判断返回信息,如果OK制卡成功,否制卡失败
if uppercase(Trim(vFErrCode))='OK' then
begin
a:=a+1;
Fmakecard_msg.Label2.Caption :='成功:'+inttostr(a);
//个人编号和卡号储存起来,退出时更新主界面中的信息
vsac100stringList.Add(VAAC001);
vakc020stringList.Add(vack020);
end
else
begin
b:=b+1;
Fmakecard_msg.memo1.Lines.Add('个人序号:'+Vaac001+':'+'姓名:'+ Vaac003 +':'+ Vaac004 +':'+vFErrCode+#13) ;
Fmakecard_msg.Label3.Caption :='失败:'+inttostr(b);
end;
//进度条增加
Fmakecard_msg.ProgressBar1.Position:=Fmakecard_msg.ProgressBar1.Position+1;
Fmakecard_msg.ADS_a.Next;
end;
end;
//关闭按牛打开
Fmakecard_msg.Button1.Enabled :=True;
end;
end.