读取大文档的问题(50分)

  • 主题发起人 主题发起人 sunshinebbs
  • 开始时间 开始时间
S

sunshinebbs

Unregistered / Unconfirmed
GUEST, unregistred user!
我有很多2M、3M以上的文档,我如何快速读入memo
 
很占用资源
建议分页读取.
 
就是文档太大,读取的时候基本界面死锁,有什么好的办法
 
可以用Tstringlist的吧。。
 
创建缓冲
 
2,3m不是很大啊,不需要内存映射吧
 
不会吧``才那么点就死锁?
你的代码肯定有问题```
 
可以提供简单代码我吗。我的代码只有一行
procedure TForm1.FileListBox1Click(Sender: TObject);
begin
memo1.Lines.LoadFromFile(filelistbox1.FileName);
end;
 
直接装入就是最快的,想办法转换再装就更慢。
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;

type
TForm1 = class(TForm)
Memo1: TMemo;
OpenDialog1: TOpenDialog;
BitBtn1: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
private
function open_file(f_name :string;memostr:Tmemo):boolean;//定义读入文件函数
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

{ TForm1 }

function TForm1.open_file(f_name: string;memostr:TMemo): boolean;
var File_str:Textfile;
tempstr :string;
begin
try
Screen.Cursor := crHourGlass;
AssignFile(File_str, f_name);
Reset(File_str);
application.ProcessMessages ;
while not eof(file_str) do
begin
Readln(File_str, tempstr);
memostr.Lines.Add(tempstr);
end;
finally
CloseFile(File_str);
Screen.Cursor:= crDefault;
end;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
opendialog1.Filter :='files(.txt)|*.txt';
if opendialog1.Execute then
open_file(opendialog1.FileName,memo1);
end;

end.
 
to:eloveme
虽然可以看到读入过程,但鼠标依然是漏洞停住,而且界面不能动
 
比以前读取时间长了好多倍
 
换个控件吧,用RichEdit
如果读入的内容是纯文本,用TStringList读入,然后用RichEdit1.text:=StringList1.text
 
tmemo有大小限制的,好像64K吧,如果不需要顯示,就不要用可視化控件讀取
 
那就把上面那个函数写入线程吧``呵呵```
 
var
Form1: TForm1;
Str:TStringList;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
if opendialog1.Execute then
Str.LoadFromFile(opendialog1.FileName);
end;

读入后出错!
 
呵呵,原来忘记了创建
是比memo的速度快一倍以上,观察多几天,没有好的方法就散分
 
用mapfile,直接把文件映射到内存。然后用类型转换,传到memo.text。但是比较麻烦
 
后退
顶部