procedure ExecCount.Execute ;
begin
intI:=0;
CoInitialize(nil);
FreeOnTerminate :=True;//线程终止时自动删除对象
StoreCount.Parameters.ParamByName('@byvStartDate').Value:=formatdatetime('yyyy-mm-dd',BeginDate);
StoreCount.Parameters.ParamByName('@byvEndDate').Value:=formatdatetime('yyyy-mm-dd',EndDate);
StoreCount.Parameters.ParamByName('@byvDept').Value:='';
StoreCount.Parameters.ParamByName('@byvPerson_Number').Value:=Person;
StoreCount.ExecProc;
intI:=1;
CountFrm.Close;
end;//上面线程执行部份 while not qryFind.Eof do
begin
Date1:=BeginDate.Date;
Date2:=EndDate.Date;
Dept1:='';
Person1:=qryFind.fieldbyname('工号').asstring;
ExecStore.Create(ManageData,Date1,Date2,Dept1,Person1); //调用线程
Gauge1.Progress:=Gauge1.Progress+1;
qryFind.Next;
end;但会报错, 异步执行时操作不能被执行?大家说下怎么改下呢,请多提提建议吧
begin
intI:=0;
CoInitialize(nil);
FreeOnTerminate :=True;//线程终止时自动删除对象
StoreCount.Parameters.ParamByName('@byvStartDate').Value:=formatdatetime('yyyy-mm-dd',BeginDate);
StoreCount.Parameters.ParamByName('@byvEndDate').Value:=formatdatetime('yyyy-mm-dd',EndDate);
StoreCount.Parameters.ParamByName('@byvDept').Value:='';
StoreCount.Parameters.ParamByName('@byvPerson_Number').Value:=Person;
StoreCount.ExecProc;
intI:=1;
CountFrm.Close;
end;//上面线程执行部份 while not qryFind.Eof do
begin
Date1:=BeginDate.Date;
Date2:=EndDate.Date;
Dept1:='';
Person1:=qryFind.fieldbyname('工号').asstring;
ExecStore.Create(ManageData,Date1,Date2,Dept1,Person1); //调用线程
Gauge1.Progress:=Gauge1.Progress+1;
qryFind.Next;
end;但会报错, 异步执行时操作不能被执行?大家说下怎么改下呢,请多提提建议吧
Use
SyncObjs;在执行线程时
用临界区来控制线程同步
EnterCriticalSection()LeaveCriticalSection()
procedure ExecCount.Execute ;
var
InterlockedCrit : TRTLCriticalSection;
begin
intI:=0;
CoInitialize(nil);
FreeOnTerminate :=True;//线程终止时自动删除对象
EnterCriticalSection(InterlockedCrit); //进入临界区
StoreCount.Parameters.ParamByName('@byvStartDate').Value:=formatdatetime('yyyy-mm-dd',BeginDate);
StoreCount.Parameters.ParamByName('@byvEndDate').Value:=formatdatetime('yyyy-mm-dd',EndDate);
StoreCount.Parameters.ParamByName('@byvDept').Value:='';
StoreCount.Parameters.ParamByName('@byvPerson_Number').Value:=Person;
StoreCount.ExecProc;
LeaveCriticalSection(InterlockedCrit); //离开临界区
intI:=1;
end; 但是会报错啊,‘Access violation at address 7C938FEA in module 'ntdll.dll' Write of address 00000010'
在网上一找'7C938FEA'都是一些乱七八糟的答案,说什么用优化大师优化一下就可解决。
有哪位朋友也曾遇到过呢?
CoInitialize(nil);
//**FreeOnTerminate := True; //这一句放到线程的构造器中
with TADOStoredProc.Create(nil) do
try
Connection := YourADOConnection;
Parameters.ParamByName('@byvStartDate').Value := formatdatetime('yyyy-mm-dd', BeginDate);
Parameters.ParamByName('@byvEndDate').Value := formatdatetime('yyyy-mm-dd', EndDate);
Parameters.ParamByName('@byvDept').Value := '';
Parameters.ParamByName('@byvPerson_Number').Value := Person;
ExecProc;
finally
CoUninitialize();
Free;
end;
intI := 1;
CountFrm.Close;