亂碼原因:本人使用的是繁體操作系統
源代碼:
code :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Edit2: TEdit;
Label2: TLabel;
Edit3: TEdit;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
function getminandmax(str1:string):string;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.getminandmax(str1: string): string;
var str1array:array of Integer;
str2array:array of Integer;
stringlist1:TStringList ;
i,small1,biger1,mid1:Integer;
strcount_s,strcount_d:Integer;
begin
try
try
stringlist1:=Tstringlist.Create;
stringlist1.Delimiter :=',';
stringlist1.DelimitedText:=str1 ;
if stringlist1.Count<3 then
begin
ShowMessage('ぶ���计���種��ㄓ暗ゑ耕���');
EXIT;
end;
Label3.Caption :='��Τ:'+inttostr(stringlist1.Count)+' 舱计�' ;
strcount_s:= (stringlist1.Count-1) div 2; //�计�� い丁�ê�计���夹
strcount_d:= stringlist1.Count div 2; //案计��
if (stringlist1.Count mod 2)=1 then
begin
mid1:= StrToInt(stringlist1.Strings[strcount_s]);
try
SetLength (str1array,strcount_s) ; //玡���计�
SetLength (str2array,strcount_s) ; //����计�
for i:=0 to strcount_s-1 do
begin
if strtoint(stringlist1.Strings[i]) < strtoint(stringlist1.Strings[strcount_s+1+i]) then
begin
str1array[i] := StrToInt(stringlist1.Strings[i]);
str2array[i] := StrToInt(stringlist1.Strings[strcount_s+1+i]);
end
else
begin
str1array[i] := StrToInt(stringlist1.Strings[strcount_s+1+i]);
str2array[i] := StrToInt(stringlist1.Strings[i]);
end;
end;
small1:=str1array[0];
biger1:=str2array[0];
for i:=0 to strcount_s-2 do
begin
//small
if str1array[i]<str1array[i+1] then
begin
if small1<str1array[i] then
small1:=small1
else
small1:=str1array[i];
end
else
begin
if small1<str1array[i+1] then
small1:=small1
else
small1:=str1array[i+1];
end;
//lager
if str2array[i]<str2array[i+1] then
begin
if biger1<str2array[i+1] then
biger1:=str2array[i+1]
else
biger1:=biger1 ;
end
else
begin
if biger1<str2array[i] then
biger1:=str2array[i]
else
biger1:=biger1;
end;
end;
if (small1>mid1) then
Result :=IntToStr(mid1)+','+inttostr(biger1)
else if mid1>biger1 then
Result :=IntToStr(small1)+','+inttostr(mid1)
else if (small1<mid1) and (mid1<biger1) then
Result :=IntToStr(small1)+','+inttostr(biger1) ;
finally
SetLength (str1array,0) ;
SetLength (str2array,0) ;
end;
end
else
begin
try
SetLength (str1array,strcount_d) ;
SetLength (str2array,strcount_d) ;
for i:=0 to strcount_d-1 do
begin
if strtoint(stringlist1.Strings[i]) < strtoint(stringlist1.Strings[strcount_d+i]) then
begin
str1array[i] := StrToInt(stringlist1.Strings[i]);
str2array[i] := StrToInt(stringlist1.Strings[strcount_d+i]);
end
else
begin
str1array[i] := StrToInt(stringlist1.Strings[strcount_d+i]);
str2array[i] := StrToInt(stringlist1.Strings[i]);
end;
end;
small1:=str1array[0];
biger1:=str2array[0];
for i:=0 to strcount_d-2 do
begin
//small
if str1array[i]<str1array[i+1] then
begin
if small1<str1array[i] then
small1:=small1
else
small1:=str1array[i];
end
else
begin
if small1<str1array[i+1] then
small1:=small1
else
small1:=str1array[i+1];
end;
//lager
if str2array[i]<str2array[i+1] then
begin
if biger1<str2array[i+1] then
biger1:=str2array[i+1]
else
biger1:=biger1 ;
end
else
begin
if biger1<str2array[i] then
biger1:=str2array[i]
else
biger1:=biger1;
end;
end;
Result :=IntToStr(small1)+','+inttostr(biger1) ;
finally
SetLength (str1array,0) ;
SetLength (str2array,0) ;
end;
end;
except
ShowMessage('叫�砏絛块�计��だ澄才ノ璣ゅ�篈��硆腹'',''');
end;
finally
FreeAndNil(stringlist1);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var str11:string;
begin
str11:=getminandmax(TrimLeft(TrimRight(Edit1.Text ))) ;
if Pos(',',str11)>0 then
begin
Edit2.Text :=Copy(str11,1,Pos(',',str11)-1);
Edit3.Text :=Copy(str11,Pos(',',str11)+1,20);
end;
end;
end.
FORM:
object Form1: TForm1
Left = 386
Top = 281
Width = 471
Height = 171
Caption = '�舱计い�程��㎝程��'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 56
Top = 63
Width = 25
Height = 17
AutoSize = False
Caption = 'MIN'
end
object Label2: TLabel
Left = 230
Top = 61
Width = 33
Height = 17
AutoSize = False
Caption = 'MAX'
end
object Label3: TLabel
Left = 48
Top = 32
Width = 345
Height = 17
Alignment = taCenter
AutoSize = False
end
object Edit1: TEdit
Left = 2
Top = 2
Width = 452
Height = 21
ImeName = 'いゅ(?蔨) - 穓���?�猭'
TabOrder = 0
Text = '88,14,25,1,2,8,7,889,44,1222,444,1111,10,21212'
end
object Button1: TButton
Left = 192
Top = 96
Width = 75
Height = 25
Caption = '絋﹚'
TabOrder = 1
OnClick = Button1Click
end
object Edit2: TEdit
Left = 96
Top = 59
Width = 121
Height = 21
ImeName = 'いゅ(?蔨) - 穓���?�猭'
TabOrder = 2
end
object Edit3: TEdit
Left = 264
Top = 59
Width = 121
Height = 21
ImeName = 'いゅ(?蔨) - 穓���?�猭'
TabOrder = 3
end
end