有没有国庆的时候同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;
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;
一次性设够
用户滚动stringgrid时,实时从stringlist取出来填充stringgrid当前可见的行就行了吧另外,下面这个没有progressmessages,可能没效果的:
waitplease.Gauge1.Progress:=waitplease.Gauge1.Progress+1;