unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
stringlist:tstringlist;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses unit2;
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var avg:integer;
begin
stringlist:=tstringlist.Create ;
stringlist.loadfromfile('d:/a.txt');
avg:=stringlist.count div 10;
readtext.create(0,avg-1,'d:/1.txt');
readtext.create(avg,2*avg-1,'d:/2.txt');
readtext.create(2*avg,3*avg-1,'d:/3.txt');
readtext.create(3*avg,4*avg-1,'d:/4.txt');
readtext.create(4*avg,5*avg-1,'d:/5.txt');
readtext.create(5*avg,6*avg-1,'d:/6.txt');
readtext.create(6*avg,7*avg-1,'d:/7.txt');
readtext.create(7*avg,8*avg-1,'d:/8.txt');
readtext.create(8*avg,9*avg-1,'d:/9.txt');
readtext.create(9*avg,stringlist.count,'d:/10.txt');
stringlist.free;
end;
end.
unit Unit2;
interface
uses
Classes,unit1;
type
readtext = class(TThread)
private
begin
pos,endpos:integer;
filename:string;
{ Private declarations }
protected
procedure Execute;
override;
published
constructor create(i,j:integer;savename:string);
end;
implementation
{ Important: Methods and properties of objects in VCL can only be used in a
method called using Synchronize, for example,
Synchronize(UpdateCaption);
and UpdateCaption could look like,
procedure readtext.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread';
end;
}
{ readtext }
procedure readtext.Execute;
var list:tstringlist;
i:integer;
begin
list:=tstringlist.create;
for i:=begin
pos to endposdo
begin
list.add(form1.stringlist);
end;
list.savetofile(filename);
list.free;
end;
constructor readtext.create(i,j:integer;savename:string);
begin
inherited create(true);
FreeOnTerminate := true;
begin
pos:=i;
endpos:=j;
filename:=savename;
end;
end.
没测试过,自己看看