简单的很容易做,要好的就要一段时间了。
unit compute;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
BitBtn1: TBitBtn;
ComboBox1: TComboBox;
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
leftvalue,rightvalue,answer_OK:real;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if ((length(edit1.Text)=0) or (length(edit2.Text)=0)) then
begin
messagedlg('输入不全,请重新输入',mtinformation,[mbOK],0);
edit1.SetFocus;
end
else
begin
leftvalue:=strtofloat(edit1.Text);
rightvalue:=strtofloat(edit2.Text);
case (combobox1.ItemIndex) of
0:
answer_OK:=leftvalue+rightvalue;
1:
answer_OK:=leftvalue-rightvalue;
2:
answer_OK:=leftvalue*rightvalue;
3:
begin
if (rightvalue=0) then
begin
messagedlg('除数为零',mterror,[mbOK],0);
end
else
answer_OK:=leftvalue / rightvalue;
end;
end;
edit3.text:=floattostr(answer_OK);
end;
end;
end.