unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, Data.DB,
Vcl.Grids, Vcl.DBGrids;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
ListView1: TListView;
Edit1: TEdit;
procedure ListView1DblClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
type
thread=class(TThread)
public
front:integer; //读取线程的开始于中止位置
rear:integer;
constructor Create(a:integer;b:integer); //构造函数不能写在protected里面,只能写在public中
protected
procedure Execute; override;
end;
var
mstream:TmemoryStream;
filepath:string;
thread1,thread2,thread3,thread4:thread;
i:integer;
procedure TForm1.ListView1DblClick(Sender: TObject);
begin
opendialog1.Options:=[offilemustexist,ofpathmustexist];
if opendialog1.Execute then filepath:=opendialog1.FileName;
mStream:=TmemoryStream.Create;
mStream.loadfromfile(filepath); //把文件读入内存
thread1.Create(0,180); //创建就立即执行调用 ,错误在哪里
thread1.Resume ;
end;
constructor thread.Create(a:integer;b:integer);
begin
//front:=a;
//rear:=b;
inherited create(true);
end;
procedure thread.Execute;
var
strlist1:Tstringlist;
s:string;
c:char;
begin
inherited;
s:=' ';
i:=1;
// while (mStream.position>=front ) and (Mstream.Position<=rear ) do
while mStream.Position<=mStream.Size do
begin
mStream.Read(c,1);
s:=s+c;
if length(s)=36 then //切割后的字符串是从下标0开始存放的
begin
ExtractStrings([' '], [], PChar(s), strlist1);
with Form1.ListView1.Items.Add do
begin
caption:=inttostr(i);
subitems.Add(strlist1[0]);
subitems.Add(strlist1[1]);
subitems.Add(strlist1[2]);
end;
form1.Edit1.Text :='当前行是第'+inttostr(i)+'行,一共有141047行';
inc(i);
end;
end;
strlist1.Free;
end;
end.
我每次一运行到thread1.create(0,180)的地方,就出现地址非法访问的错误,可是我感觉的没错误呀
,求助各位大佬啦,本人实在是改不出来了