qqq(100分)

  • 主题发起人 主题发起人 qiuemail
  • 开始时间 开始时间
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.
 
楼主想问什么呀?
 
是啊。看他發了兩個貼,也不說啥,
 
strtoint产生的错误 try except 捕捉不到吧。。。。。。。。。。。
。。。。。。。。
const
Decimals = ['0'..'9'];
FloatNums = ['0'..'9', '.'];
Operators = ['+', '-', '*', '/'];
HexDecimals = ['0'..'9', 'A'..'F'];
Letters = ['a'..'z', 'A'..'Z'];
Symbols = ['"', '''', '<', '>', '{', '}', '[', ']', '(', ',', ')'];
Masks : array[1..3] of Char = ('*', '?', '#');
function EStrToInt(S: String) : Integer;
var
i : Integer;
r : String;
begin
r := '';
for i := 1 to Length(S) do
if s in Decimals then
r := r + s;
if r = '' then
Result := 0
else
Result := StrToInt(r);
end;

function EStrToFloat(S : String) : Real;
var
i : Integer;
r : String;
begin
r := '';
for i := 1 to Length(S) do
if s in FloatNums then
r := r + s;
if r = '' then
Result := 0
else
Result := StrToFloat(r);
end;
 
楼主的问题应该要标示出来呀,不知道你到底要问什么问题?
 
而且在非技术问题一类中,估计是想让大家帮数源码有多少行?
 

Similar threads

A
回复
0
查看
981
Andreas Hausladen
A
S
回复
0
查看
579
SUNSTONE的Delphi笔记
S
S
回复
0
查看
650
SUNSTONE的Delphi笔记
S
S
回复
0
查看
675
SUNSTONE的Delphi笔记
S
S
回复
0
查看
673
SUNSTONE的Delphi笔记
S
后退
顶部