|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 tanyztj 于 2017-10-13 01:47 编辑
本帖最后由 tanyztj 于 2017-10-12 21:52 编辑
unit Unit1;
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;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
Button14: TButton;
Button15: TButton;
Button16: TButton;
Button17: TButton;
Button18: TButton;
Button19: TButton;
Button20: TButton;
Button21: TButton;
Button23: TButton;
ListBox1: TListBox;
procedure FormCreate(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure Button14Click(Sender: TObject);
procedure Button15Click(Sender: TObject);
procedure Button16Click(Sender: TObject);
procedure Button19Click(Sender: TObject);
procedure Button18Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button17Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Button20Click(Sender: TObject);
procedure Button21Click(Sender: TObject);
procedure Button23Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
var
data,data1,data2:Real;
OK:Integer;
StrO:string='0';
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
//edit1输入居中
SetWindowLong(Edit1.handle, GWL_STYLE, GetWindowlong(edit1.Handle, GWL_STYLE)+ES_CENTER);
Edit1.Refresh;
end;
procedure TForm1.Button5Click(Sender: TObject); //1
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:='';
Edit1.Text:=Edit1.Text +'1';
end;
OK:=0;
end;
procedure TForm1.Button6Click(Sender: TObject); //2
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:='';
Edit1.Text:=Edit1.Text +'2';
end;
OK:=0;
end;
procedure TForm1.Button7Click(Sender: TObject); //3
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:='';
Edit1.Text:=Edit1.Text +'3';
end;
OK:=0;
end;
procedure TForm1.Button8Click(Sender: TObject); //4
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:='';
Edit1.Text:=Edit1.Text +'4';
end;
OK:=0;
end;
procedure TForm1.Button9Click(Sender: TObject); //5
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:='';
Edit1.Text:=Edit1.Text +'5';
end;
OK:=0;
end;
procedure TForm1.Button10Click(Sender: TObject); //6
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:='';
Edit1.Text:=Edit1.Text +'6';
end;
OK:=0;
end;
procedure TForm1.Button11Click(Sender: TObject); //7
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:='';
Edit1.Text:=Edit1.Text +'7';
end;
OK:=0;
end;
procedure TForm1.Button12Click(Sender: TObject); //8
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:='';
Edit1.Text:=Edit1.Text +'8';
end;
OK:=0;
end;
procedure TForm1.Button13Click(Sender: TObject); //9
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:='';
Edit1.Text:=Edit1.Text +'9';
end;
OK:=0;
end;
procedure TForm1.Button14Click(Sender: TObject); //0
begin
if Edit1.Text ='' then
MessageBeep(MB_OK)
else
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:=''
else
Edit1.Text:=Edit1.Text +'0';
end;
end;
OK:=0;
end;
procedure TForm1.Button15Click(Sender: TObject); //00
begin
if Edit1.Text ='' then
MessageBeep(MB_OK)
else
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
Edit1.Text:=''
else
Edit1.Text:=Edit1.Text +'00';
end;
end;
OK:=0;
end;
procedure TForm1.Button16Click(Sender: TObject); //.
begin
if Edit1.Text ='' then
Edit1.Text:= '0.'
else
begin
if Length(Edit1.Text)> 40 then
MessageBeep(MB_OK)
else
begin
if OK =1 then
begin
Edit1.Text:='';
Edit1.Text:= '0.';
end
else
Edit1.Text:=Edit1.Text +'.';
end;
end;
OK:=0;
end;
procedure TForm1.Button19Click(Sender: TObject);
begin
Edit1.Text:='';
OK:=0;
end;
procedure TForm1.Button18Click(Sender: TObject);
begin
Close;
end;
procedure TForm1.Button1Click(Sender: TObject); //+
var
i:Integer;
begin
i:=Length(Edit1.Text);
if Edit1.Text='' then
MessageBeep(MB_OK)
else
begin
if (Edit1.Text='+')or (Edit1.Text='-')or
(Edit1.Text='*')or (Edit1.Text='*') then
MessageBeep(MB_OK)
else
Edit1.Text:=Edit1.Text+'+';
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
i:Integer;
begin
i:=Length(Edit1.Text);
if Edit1.Text='' then
MessageBeep(MB_OK)
else
begin
if (Edit1.Text='+')or (Edit1.Text='-')or
(Edit1.Text='*')or (Edit1.Text='*') then
MessageBeep(MB_OK)
else
Edit1.Text:=Edit1.Text+'-';
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
i:Integer;
begin
i:=Length(Edit1.Text);
if Edit1.Text='' then
MessageBeep(MB_OK)
else
begin
if (Edit1.Text='+')or (Edit1.Text='-')or
(Edit1.Text='*')or (Edit1.Text='*') then
MessageBeep(MB_OK)
else
Edit1.Text:=Edit1.Text+'*';
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var
i:Integer;
begin
i:=Length(Edit1.Text);
if Edit1.Text='' then
MessageBeep(MB_OK)
else
begin
if (Edit1.Text='+')or (Edit1.Text='-')or
(Edit1.Text='*')or (Edit1.Text='*') then
MessageBeep(MB_OK)
else
Edit1.Text:=Edit1.Text+'/';
end;
end;
procedure TForm1.Button17Click(Sender: TObject);
var
i:string;
mun:array[1..40] of Real;
mun1:array[1..40] of string;
L,j,a,k:Integer;
begin
a:=1;
j:=1;
OK:=1;
k:=1;
L:=1;
for a:=1 to Length(Edit1.Text) do
begin
if (Edit1.Text[a]='+') or (Edit1.Text[a]='-') or
(Edit1.Text[a]='*') or (Edit1.Text[a]='/') then
begin
mun[j]:= StrToFloat(i);
mun1[L]:= Edit1.Text[a];
j:=1+j;
L:=1+L;
i:='';
end
else
i:=i+ Edit1.Text[a];
end;
mun[j]:= StrToFloat(i);
data:= mun[1];
for a:=2 to j do
begin
data1:= mun[a];
if mun1[k]='+' then
data2:=data+data1
else if mun1[k]='-' then
data2:=data-data1
else if mun1[k]='*' then
data2:=data*data1
else if mun1[k]='/' then
data2:=data/data1;
k:=k+1;
data:= data2;
end;
Edit1.Text:=Edit1.Text+'='+floattostr(data2);
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
If not(key in ['0'..'9',#8,#43,#45,#42,#47,#46,#187,#13]) then // #8 表示Delete键
Begin
Key:= #0; // #0 表示没有输入
MessageBeep(MB_OK);
End;
end;
procedure TForm1.Button20Click(Sender: TObject);
begin
Edit1.Text := Copy(Edit1.Text,0,Length(Edit1.Text)-1);
Edit1.SetFocus;
Edit1.SelStart := Length(Edit1.Text);
end;
procedure TForm1.Button21Click(Sender: TObject);
begin
if edit1.text <> stro then listBox1.AddItem(edit1.text,sender);
end;
procedure TForm1.Button23Click(Sender: TObject);
begin
listBox1.Clear;
end;
end.
解决了很多问题,现在有二个问题:
1、上面复制那个问题没解决。(我现在粘上的代码去掉了这部分)
2、我想实现按回车键就显示计算结果,怎么做?谢谢大大
3、还有个问题,比如显示的是这样的内容:2*6=12,我想在另一个Label中只取=号后面的结果,可以吗?怎么做?谢谢
|
|