+ -
当前位置:首页 → 问答吧 → delphi 线程 access violation at address

delphi 线程 access violation at address

时间:2011-08-17

来源:互联网

最近用DELPHI写一个线程的程序,会不定时出现access violation at address 后面的地址经常不一样,有时候是00000000,有时候是其他的,请大虾们帮忙看下下面的程序有什么问题

//-------------定义线程-------------------------------
 type
  TMyThread = class(TThread)
  protected
  procedure Execute; override;
  end;

procedure TMyThread.Execute;
var
tmpList:TStringList;
  index,row:Integer;
begin

FreeOnTerminate := True;
 if NewMsgBox.OpenDialog1.Execute then //获取文件的路径
  begin
  if waitplease = nil then
  waitplease:= Twaitplease.Create(nil);
  waitplease.Show; //显示进度条的窗体
  tmpList:=TStringList.Create;
  tmpList.LoadFromFile(NewMsgBox.OpenDialog1.FileName); //把文本文件导入StringList;
  row:=NewMsgBox.PhoneGrid.RowCount; //NewMsgBox中StringGrid的行数
  waitplease.Gauge1.Visible := true; //设置进度条相关属性
  waitplease.Gauge1.Invalidate;
  waitplease.Gauge1.Progress := 0;
  waitplease.Gauge1.MaxValue := tmpList.Count-1;
  for index:=0 to tmpList.Count-1 do //把StringList中的内容循环读近NewMsgBox的StringGrid
  begin
  if CheckPhoneNumber(tmpList[index]) then
  begin
  NewMsgBox.PhoneGrid.Cells[0,row]:=tmpList[index];
  row:=row+1;
  NewMsgBox.PhoneGrid.RowCount:=row;
  end;
  waitplease.Gauge1.Progress:=waitplease.Gauge1.Progress+1; //进度条+1
  end;
  waitplease.close; //关闭进度条
  tmpList.Free; //释放STRINGLIST
  end;


end;



//----------------调用线程----------------------

TMyThread.Create(False);

作者: younerest   发布时间: 2011-08-17

晕,你在子线程中调用主线程中的东西你都不加同步当然会出错啊!加同步试试!

作者: jayqiang   发布时间: 2011-08-18

热门下载

更多