如题,如果是第三方支持的,请给一个下载地址
解决方案 »
- 请问一下,如何全盘查找文件?
- 以下的报表如何用fastreport实现?
- 庆祝:散光可用分
- 我想找些PP的图标,让软件做得漂亮些。但是我在网上搜索了一下,没有发现特别好的,能给点建议吗?
- 这个SQL语句哪儿有错,我用ACCESS2000执行怎么不对?
- 请问有没有关于Windows API与Delphi相关的书呀?
- 请教一个关于dbgrid的问题
- 请教delphi 的全局,局部变量怎么定义的,以及窗口间如何传递参数
- 请问各位:如何将DBGrid的中的内容读入到二维数组中
- HELP!!!!!!!!!!
- SQL SERVER用ADO连接后,如何解决RECORDNO为-1的问题
- 各位高手,谁对nil有研究,请教isnull()的用法
楼主一定要给满一百分哦.
//说明一个:下面例子在窗体上加两个Edit,一个Button,Edit1中为输入的表达式,支持所有运算符,包括"()",Edit2为输出结果
unit compute;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Math;type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
procedure Button1Click(Sender: TObject); private
{ Private declarations }
s: string;
function GetNumber(): real;
function comp(a, b: char): char;
function cal(a, b: real; p: char): real;
function expr(): real;
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
var r: real;
begin
s := edit1.Text; //edit1中为要求值的表达式
r := expr(); // 调用求值函数
edit2.Text := floattostr(r); //将求值结果写到eidt2中
end;function TForm1.cal(a, b: real; p: char): real;
begin
case p of
'+': result := a + b;
'-': result := a - b;
'*': result := a * b;
'/':
begin
if b = 0 then
begin
showmessage('除数为0');
result := 0;
end
else
result := a / b;
end;
end;
end;function TForm1.comp(a, b: char): char;
begin
if not (a in ['+', '-', '*', '/', '(', ')', '#']) or not (b in ['+', '-', '*', '/', '(', ')', '#']) then result := 'e'
else
case a of
'+', '-': case b of
'*', '/', '(': result := '<';
else result := '>';
end;
'*', '/': if b = '(' then result := '<' else result := '>';
'(': if b = ')' then result := '=' else if b = '#' then result := 'e' else result := '<';
')': if b = '(' then result := 'e' else result := '>';
'#': if b = ')' then result := 'e' else if b = '#' then result := 'R' else result := '<';
end;
end;
function TForm1.expr(): real;
var
res, ch: char;
oprTop, numTop: integer;
opr: array[1..100] of char;
num: array[1..100] of real;begin opr[1] := '#';
s := s + '#';
oprTop := 1;
numTop := 0;
res := ' ';
repeat
if s[1] in ['0'..'9'] then
begin
inc(numTop);
num[numTop] := GetNumber();
end
else
begin
ch := s[1];
delete(s, 1, 1);
repeat
res := comp(opr[oprTop], ch);
case res of
'>': begin
num[numTop - 1] := cal(num[numTop - 1], num[numtop], opr[oprTop]);
dec(numTop);
dec(oprTop);
end;
'<': begin
inc(oprTop);
opr[oprTop] := ch;
end;
'=': begin
dec(oprTop);
end;
'e': begin
showmessage('表达式出错!');
result := 0;
exit;
end;
'R': begin
result := num[numTop];
end;
end;
until res <> '>';
end;
until res = 'R';
end;
function TForm1.GetNumber(): real;
var
i, code: integer;
begin
i := 1;
while (i <= length(s)) and (s[i] in ['0'..'9', '.']) do inc(i);
val(copy(s, 1, i - 1), result, code);
delete(s, 1, i - 1);
end;
end.