unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
OpenDialog1: TOpenDialog;
Edit2: TEdit;
Button2: TButton;
Button3: TButton;
Label1: TLabel;
Edit3: TEdit;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
TAA,TBB:tstringlist;
implementation
{$R *.dfm}
//比较两个字串
function bijiao(const S1,S2:string):integer;
var
I,R:integer;
begin
I:=1;
R:=0;
while I<=length(S2) do
begin
if (S1=S2) then Inc(R);
Inc(I);
end;
Result:=R;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
TAA:=tstringlist.Create;
TBB:=tstringlist.Create;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
TAA.Free;
TBB.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if opendialog1.Execute then
TAA.LoadFromFile(opendialog1.FileName);
Edit1.Text:=inttoStr(TAA.Count);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if opendialog1.Execute then
TBB.LoadFromFile(opendialog1.FileName);
Edit2.Text:=inttoStr(TBB.Count);
end;
procedure TForm1.Button3Click(Sender: TObject);
var
I,J,ST,ET,N,NA,NB:integer;
S1,S2:string;
begin
ST:=gettickcount;
NA:=TAA.Count;
NB:=TBB.Count;
for I:=0 to NA-1 do
begin
for J:=0 to NB-1 do
begin
S1:=TAA.Strings;
S2:=TBB.Strings[J];
N:=bijiao(S1,S2);
end;
Edit3.Text:=formatfloat('0%',I/NA*100);
application.ProcessMessages;
end;
ET:=gettickcount;
Edit3.Text:=InttoStr(ET-ST)+'毫秒';
end;
end.