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);
//-------------定义线程-------------------------------
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
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28