在主窗口中新建一个对串口实时采集数据的线程,大部份时候正常。
但是有时候会出现“out of resource systems”的错误提示框,并且提示窗口一个接一个的显示出来,感觉象死机一样。不过不停的按回车,可关闭对话框。但马上又会弹出。我估计程序可能进入一个死循环。查了N遍也查不出个所以然,请教各位大虾,帮帮我!!!
但是有时候会出现“out of resource systems”的错误提示框,并且提示窗口一个接一个的显示出来,感觉象死机一样。不过不停的按回车,可关闭对话框。但马上又会弹出。我估计程序可能进入一个死循环。查了N遍也查不出个所以然,请教各位大虾,帮帮我!!!
Synchronize()这个函数用的比较多,是不是它出了问题?线程代码如下:
procedure TRealCtrlThr.Execute;
begin
AD_No:=0; MD:=0; PgNo:=0; SVoltNo:=0;
while True do
begin
if Terminated then Break;
if PauseYN then Continue;
if Suspended then Continue; PerForm_Thr();
end;
end;procedure TRealCtrlThr.PerForm_Thr();
var
i:Integer;
begin
case PgNo of
0..3:begin
Thr_BoxNo := 0;
for i:=0 to gModuleTotal-1 do
begin
Thr_BoxNo := i;
//启动电子负载
if PauseYN then Break;
if StartUpEload() then Break; //读取实时数据
if PauseYN then Break; if not ReadData() then Continue; //数据入库
if PauseYN then Break;
Synchronize(WriteDB); //实时刷新
if PauseYN then Break; if gInterFace=UpperCase('Frm_StartUp_F10') then Synchronize(RealTimeGraphF10);
if gInterFace=UpperCase('Frm_StartUp_F10A') then Synchronize(RealTimeGraphF10A);
if gInterFace=UpperCase('Frm_StartUp_F200') then Synchronize(RealTimeGraphF200);
if gInterFace=UpperCase('Frm_StartUp_F5000') then Synchronize(RealTimeGraphF5000);
end;
end;
4:Synchronize(Jdts_XS); //精度调试
5:begin //PID整定
if (gInterFace=UpperCase('Frm_StartUp_F10')) and (Frm_StartUp_F10<>Nil) then Synchronize(Jdts_PID);
if (gInterFace=UpperCase('Frm_StartUp_F10A')) and (Frm_StartUp_F10A<>Nil) then Synchronize(Jdts_PID);
if (gInterFace=UpperCase('Frm_StartUp_F200')) and (Frm_StartUp_F200<>Nil) then Synchronize(Jdts_PID);
if (gInterFace=UpperCase('Frm_StartUp_F5000')) and (Frm_StartUp_F5000<>Nil) then Synchronize(Jdts_PID);
end;
end;
end;
但这也不仅仅是内存不够的问题.也有可能是内存冲突
你在使用自动创建资源后,一定要Free掉.
因为在读串口时有延时的操作,Sleep(300).
Read_Buf:Array of Byte;
i: Integer;
begin
try
SetLength(Read_Buf,gLen); //gLen 全局变量
for i:=0 to Len-1 do Read_Buf[i] := gData_Buf[i]; //gData_Buf 全局变量........finally
//在这我没加 SetLength(Read_Buf,0); 这句话,不加这句话对内存有影响吗?
end;
end;