out of Memory

younerest 2011-10-05 10:57:01
有没有国庆的时候同LZ一样在悲催加班的大虾,能不能帮我看下一下程序:在TMyThread中把文本文件通过StringList在StringGrid中显示。当文本文件有600000行的时候,在导入到40%左右的时候就提示:Projece ss.exe raised exception class EOutOfMemory with message 'Out of memory'。大虾们能不能帮我看下是什么原因。


procedure TMyThread.Execute;
var
tmpList:TStringList;
index,row:Integer;
originalrow:integer;
repeatcount:integer;
begin
FreeOnTerminate := True; {这可以让线程执行完毕后随即释放}
if NewMsgBox.OpenDialog1.Execute then//选择文本文件
begin
tmpList:=TStringList.Create;//初始化StringList
tmpList.LoadFromFile(NewMsgBox.OpenDialog1.FileName);//导入文本文件到StringList
if tmpList.Count=0 then //文本文件为空 则退出
begin
exit;
end
else
begin
row:=NewMsgBox.PhoneGrid.RowCount;
NewMsgBox.PhoneGrid.RowCount:=NewMsgBox.PhoneGrid.RowCount+tmpList.Count;
for index:=0 to tmpList.Count-1 do //把TstringList的内容写入PhoneGrid PhoneGrid为StringGrid
begin
NewMsgBox.PhoneGrid.Cells[0,row]:=tmpList[index];
row:=row+1;
waitplease.Gauge1.Progress:=waitplease.Gauge1.Progress+1;
end;
end;
tmpList.Free;

end;


end;
...全文
206 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
haitao 2011-10-05
  • 打赏
  • 举报
回复
哦,看错了

要不要真的全部加载到stringgrid?
用户滚动stringgrid时,实时从stringlist取出来填充stringgrid当前可见的行就行了吧

另外,下面这个没有progressmessages,可能没效果的:
waitplease.Gauge1.Progress:=waitplease.Gauge1.Progress+1;
cntigercat 2011-10-05
  • 打赏
  • 举报
回复
加个大内存条,哈哈
haitao 2011-10-05
  • 打赏
  • 举报
回复
不要row:=row+1;
一次性设够
vokeyliu 2011-10-05
  • 打赏
  • 举报
回复
你这个一股脑的把所有东西通通塞入内存,肯定会有问题啊,建议考虑分段显示,即一次显示多少条记录
shijies 2011-10-05
  • 打赏
  • 举报
回复
内存不足,文件是否很大?

16,747

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧