最近用DELPHI写一个线程的程序,会不定时出现access violation at address 后面的地址经常不一样,有时候是00000000,有时候是其他的,请大虾们帮忙看下下面的程序有什么问题//-------------定义线程-------------------------------
type
TMyThread = class(TThread)
protected
procedure Execute; override;
end;procedure TMyThread.Execute;
var
tmpList:TStringList;
index,row:Integer;
beginFreeOnTerminate := 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;
beginFreeOnTerminate := 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);
解决方案 »
- DB2如何实现交叉表呢?
- delphi开发ocx的控件如何打包成cab的包,以便在IE上直接下载啊
- 这是不是delphi的bug?欢迎高手前来讨论!
- 高分求答,UP有分,关于MTs/Com+ 中为什么我的客户端在调用MTs组件时 如果是在IDE环境中运行那么就进入了一个怎么着都出不来结
- 将Timage控件中的图片保存到oracle中。用query。
- 发现个很大的秘密:大家快来看啊!!!
- 如果在两个窗体之间传递对象指针或类指针
- 郁闷,散分!!!!!!
- 关于打印的问题,请指教!
- Pdoxusrs.lck,Paradox.lck的秘密在哪里? 为什么在LAN中使用时,时不时出现该文件被其它用户控制的提示?
- 我的\Program Files\Common Files\Borland Shared\Database Desktop\DBD32.EXE文件损坏
- delphi中treeview如何让指定节点在复选框默认打钩。
你线程是不是有Terminate,FreeOnTerminate := True;
这个会把线程Free的
你是不是又有唤醒代码拉
TMyThread = class(TThread)
protected
procedure Execute; override;
end;procedure TMyThread.Execute;
var
tmpList:TStringList;
index,row:Integer;
beginFreeOnTerminate := 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;
NewMsgBox.PhoneGrid.RowCount:=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;
自己弄好了PhoneGrid的行数每次循环增加一行导致出错,后来我在循环前面先把PhoneGrid的行数给定下来就好了。还是谢谢各位!