procedure TForm1.Button2Click(Sender: TObject);
var
MyFile:textfile;
MyStr:array of String;
MyTmp:string;
i,j,Y:integer;
kkk,jjj:int64;
flag:boolean;
begin
if form1.OpenDialog1.Execute then
begin
AssignFile(MyFile,form1.OpenDialog1.FileName);
Reset(MyFile);
Y:=-1;
While Not EOF(MyFile) do
begin
Readln(MyFile,MyTmp);
Y:=Y+1;
end;
CloseFile(MyFile);
setlength(MyStr,Y+2);
AssignFile(MyFile,form1.OpenDialog1.FileName);
Reset(MyFile);
try
i:=0;
while not Eof(MyFile) do
begin
Readln(MyFile,MyStr[i]);
Inc(i);
end;
finally
CloseFile(MyFile);
end;
try
For j:= Y do
wnto 0 do
begin
flag:=False;
For i:= 0 to Y do
begin
if(strlen(pchar(MyStr[i+1]))<5) then
MyStr[i+1]:='00000000000000000000000000000';
label1.caption:=inttostr(j);
application.ProcessMessages;
kkk:=strtoint64(copy(MyStr[i],1,3)+'000000')+strtoint64(copy(MyStr[i],5,3)+'000')+strtoint64(copy(MyStr[i],9,3));
jjj:=strtoint64(copy(MyStr[i+1],1,3)+'000000')+strtoint64(copy(MyStr[i+1],5,3)+'000')+strtoint64(copy(MyStr[i+1],9,3));
if kkk<jjj then
begin
mytmp:=MyStr[i];
MyStr[i]:=MyStr[i+1];
Mystr[i+1]:=Mytmp;
flag:=True;
end;
end;
if Flag=False then
break;
end;
copyfile(pchar(ExtractFileName(OpenDialog1.FileName)),pchar(ExtractFileName(form1.OpenDialog1.FileName)+'.bak'),False);
AssignFile(MyFile,form1.OpenDialog1.FileName);
Rewrite(MyFile);
try
For i:= 0 to Y do
begin
writeln(MyFile,MyStr[i]);
end;
finally
CloseFile(MyFile);
end;
button2.caption:='完成!';
finally
MyStr:=nil;
end;
end;
end;