Q
qiuemail
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit_test;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
end;
var
Form1: TForm1;
//自定义函数
function Integer_judge( Src:string): Boolean;
function YunSuanFu_judge( Src:string;i:integer): boolean;
function Y_judge( Src:string;Src_len,i,i_new:integer): boolean;
function Num_value( Src:string;Src_len,i,i_new:integer): integer;
implementation
{$R *.dfm}
//数字
function Integer_judge( Src:string): Boolean;
var
astring:string;
ainteger:integer;
begin
astring:=Src;
//是否为整型
try
ainteger:=strtoint(astring);
// if ainteger>0 then
result:=true;
//else
// result:=false;
except
result:=false;
end ;
end;
function YunSuanFu_judge( Src:string;i:integer): boolean;
var
str_ls:string;
begin
//判断是否为数字 是数字则累加到一变量中
str_ls:=copy(Src,i+1,1);
if Integer_judge(str_ls) then
begin
//if strtoint(str_ls)>0 then
// result:=true;
end
else
begin
showmessage('*后面应跟正整数');
result:=false;
end;
end;
function Num_value( Src:string;Src_len,i,i_new:integer): integer;
var
str_ls:string;
str_lj:string;
j:integer;
begin
str_lj:='';
while i<Src_len do
begin
str_ls:=copy(Src,i,1);
if Integer_judge(str_ls) then
begin
str_lj:=str_lj+str_ls;
i:=i+1;
// showmessage('1');//continue;
end
else
begin
i_new:=j;
break;
end;
end;
i_new:=i;
result:=strtoInt(str_lj);
end;
function Y_judge( Src:string;Src_len,i,i_new:integer): boolean;
var
str_ls:string;
str_lj:string;
j:integer;
//i_new:integer;
begin
//判断是否为数字 是数字则累加到一变量中
str_ls:=copy(Src,i+1,1);
if Integer_judge(str_ls) then
begin
if strtoint(str_ls)>0 then
begin
Num_value( Src,Src_len,i+1,i_new);//
i:=i_new;
str_ls:=copy(Src,i+1,1);
if str_ls='*' then
if YunSuanFu_judge(Src,i) then
result:=true
else
result:=false
else
showmessage('Y后面应跟算式');
end
else
begin
showmessage('*后面应跟正整数');
result:=false;
end;
end
else
//if Integer_judge(str_ls) then
begin
showmessage('*后面应跟正整数');
result:=false;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
astring:string;
ainteger:integer;
begin
astring:=edit1.Text;
//是否为整型
try
ainteger:=strtoint(astring);
except
edit1.setfocus;
end ;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
I, Code: Integer;
begin
Val(Edit1.Text, I, Code);
if Code <> 0 then
MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0)
else
Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I));
end;
procedure TForm1.Button3Click(Sender: TObject);
var
str_edit:string;
str_edit_length:integer;
i,j,i_new:integer;
str_ls:string;
str_lj:string;//累加
begin
str_edit:=edit1.Text;
str_edit_length:=length(str_edit);
str_lj:='';
i:=0;
while (i<str_edit_length) do
begin
str_ls:=copy(str_edit,i,1);
//若为数字则下一个字符
if Integer_judge(str_ls) then
begin
showmessage(inttostr( num_value(str_edit,str_edit_length,i,i_new)));
showmessage(inttostr(i_new));
showmessage('shuzi');
end;
//不为数字,则判断算符
if (str_ls='*') or (str_ls ='/') then
begin
//判断是否为数字
if YunSuanFu_judge(str_edit,i) then
continue
else
begin
showmessage('*后面应跟正整数');
exit;
end;
end;
if str_ls='Y' then
if Y_judge(str_edit,str_edit_length,i,i_new) then
continue
else
begin
showmessage('*后面应跟正整数');
exit;
end;
i:=i_new;
i:=i+1;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i_new:integer;
begin
showmessage(inttostr(Num_value( '123i456i',7,2,i_new)));
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
end;
var
Form1: TForm1;
//自定义函数
function Integer_judge( Src:string): Boolean;
function YunSuanFu_judge( Src:string;i:integer): boolean;
function Y_judge( Src:string;Src_len,i,i_new:integer): boolean;
function Num_value( Src:string;Src_len,i,i_new:integer): integer;
implementation
{$R *.dfm}
//数字
function Integer_judge( Src:string): Boolean;
var
astring:string;
ainteger:integer;
begin
astring:=Src;
//是否为整型
try
ainteger:=strtoint(astring);
// if ainteger>0 then
result:=true;
//else
// result:=false;
except
result:=false;
end ;
end;
function YunSuanFu_judge( Src:string;i:integer): boolean;
var
str_ls:string;
begin
//判断是否为数字 是数字则累加到一变量中
str_ls:=copy(Src,i+1,1);
if Integer_judge(str_ls) then
begin
//if strtoint(str_ls)>0 then
// result:=true;
end
else
begin
showmessage('*后面应跟正整数');
result:=false;
end;
end;
function Num_value( Src:string;Src_len,i,i_new:integer): integer;
var
str_ls:string;
str_lj:string;
j:integer;
begin
str_lj:='';
while i<Src_len do
begin
str_ls:=copy(Src,i,1);
if Integer_judge(str_ls) then
begin
str_lj:=str_lj+str_ls;
i:=i+1;
// showmessage('1');//continue;
end
else
begin
i_new:=j;
break;
end;
end;
i_new:=i;
result:=strtoInt(str_lj);
end;
function Y_judge( Src:string;Src_len,i,i_new:integer): boolean;
var
str_ls:string;
str_lj:string;
j:integer;
//i_new:integer;
begin
//判断是否为数字 是数字则累加到一变量中
str_ls:=copy(Src,i+1,1);
if Integer_judge(str_ls) then
begin
if strtoint(str_ls)>0 then
begin
Num_value( Src,Src_len,i+1,i_new);//
i:=i_new;
str_ls:=copy(Src,i+1,1);
if str_ls='*' then
if YunSuanFu_judge(Src,i) then
result:=true
else
result:=false
else
showmessage('Y后面应跟算式');
end
else
begin
showmessage('*后面应跟正整数');
result:=false;
end;
end
else
//if Integer_judge(str_ls) then
begin
showmessage('*后面应跟正整数');
result:=false;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
astring:string;
ainteger:integer;
begin
astring:=edit1.Text;
//是否为整型
try
ainteger:=strtoint(astring);
except
edit1.setfocus;
end ;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
I, Code: Integer;
begin
Val(Edit1.Text, I, Code);
if Code <> 0 then
MessageDlg('Error at position: ' + IntToStr(Code), mtWarning, [mbOk], 0)
else
Canvas.TextOut(10, 10, 'Value = ' + IntToStr(I));
end;
procedure TForm1.Button3Click(Sender: TObject);
var
str_edit:string;
str_edit_length:integer;
i,j,i_new:integer;
str_ls:string;
str_lj:string;//累加
begin
str_edit:=edit1.Text;
str_edit_length:=length(str_edit);
str_lj:='';
i:=0;
while (i<str_edit_length) do
begin
str_ls:=copy(str_edit,i,1);
//若为数字则下一个字符
if Integer_judge(str_ls) then
begin
showmessage(inttostr( num_value(str_edit,str_edit_length,i,i_new)));
showmessage(inttostr(i_new));
showmessage('shuzi');
end;
//不为数字,则判断算符
if (str_ls='*') or (str_ls ='/') then
begin
//判断是否为数字
if YunSuanFu_judge(str_edit,i) then
continue
else
begin
showmessage('*后面应跟正整数');
exit;
end;
end;
if str_ls='Y' then
if Y_judge(str_edit,str_edit_length,i,i_new) then
continue
else
begin
showmessage('*后面应跟正整数');
exit;
end;
i:=i_new;
i:=i+1;
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i_new:integer;
begin
showmessage(inttostr(Num_value( '123i456i',7,2,i_new)));
end;
end.