1. delphi里如何编写计算公式
edit1.text := inttostr(strtoint(label1.caption)*strtoint(label2.caption));
edit3.text := inttostr(strtoint(edit1.text)-strtoint(edit2.text));
2. 用delphi怎样编写一个简单计算器的程序?
可以用SetFocus成员函数来激活Edit是输入的字符变成数据可以用类型转换,
把字符转成数字不明白可以加Q
2723.99954讨论
3. 跪求一个用delphi7 编写的程序,可以用来实现计算功能包括加减乘除,括...
国名啊.来448
4. 用DELPHI编写 计算器的程序
你想问什么?用Delphi编写计算器的程序的过程中你遇到了什么问题?
我想我能帮你,不过你应该先把问题说清楚。
5. Delphi7的计算器代码怎么写?
//全写了注释了, 不懂追问 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, ExtCtrls; //新建一工程, 放进15个TSpeedButton和一个TEdit然后按照下边的说明设置一下. type TForm1 = class(TForm) //把窗体的KeyPreview属性设置为TRUE SpeedButton1: TSpeedButton; //表示数字键1, Caption属性设置为1 SpeedButton2: TSpeedButton; //表示数字键2, Caption属性设置为2 SpeedButton3: TSpeedButton; //表示数字键3, Caption属性设置为3 SpeedButton4: TSpeedButton; //表示数字键4, Caption属性设置为4 SpeedButton5: TSpeedButton; //表示数字键5, Caption属性设置为5 SpeedButton6: TSpeedButton; //表示数字键6, Caption属性设置为6 SpeedButton7: TSpeedButton; //表示数字键7, Caption属性设置为7 SpeedButton8: TSpeedButton; //表示数字键8, Caption属性设置为8 SpeedButton9: TSpeedButton; //表示数字键9, Caption属性设置为9 SpeedButton10: TSpeedButton; //表示数字键0, Caption属性设置为0 SpeedButton11: TSpeedButton; //表示小数点., , Caption属性设置为 . 小数点 SpeedButton12: TSpeedButton; //计算结果, 等于(=)号, Caption属性设置为 = SpeedButton13: TSpeedButton; //加号, Caption属性设置为 + , Tag属性设置为 1 SpeedButton14: TSpeedButton; //减号, Caption属性设置为 - , Tag属性设置为 2 Edit1: TEdit; //显示计算结果 SpeedButton15: TSpeedButton; //归零(复位)处理 procedure SpeedButton1Click(Sender: TObject); procedure SpeedButton12Click(Sender: TObject); procedure SpeedButton13Click(Sender: TObject); procedure SpeedButton15Click(Sender: TObject); procedure FormKeyPress(Sender: TObject; var Key: Char); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} var Flag: Boolean = True; //。标记位 Flag1: Integer = 1; //计算方法标志位 num1, num2, result: Real; flagresult: Boolean = False; procedure TForm1.SpeedButton1Click(Sender: TObject); //按住SHIFT键, 再用鼠标点SpeedButton1 至 SpeedButton11(多选), 然后在属性面板双击onClick //以后11个SpeedButton共用一个OnClick事件, var str: string; begin str := Edit1.Text; if (Length(str) = 1) and (str = '0') then Edit1.Clear; Edit1.Color := clBlue; if ((Sender as TSpeedButton).Caption = '.') then //小数点处理 begin if Flag then begin Edit1.Text := Edit1.Text + (sender as TSpeedButton).Caption; Flag := False; end end else Edit1.Text := Edit1.Text + (sender as TSpeedButton).Caption; end; procedure TForm1.SpeedButton12Click(Sender: TObject); //计算并显示结果 begin Edit1.Color := clRed; num2 := StrToFloatDef(Edit1.Text, 0.00); case Flag1 of 1: result := num1 + num2; 2: result := num1 - num2; Edit1.Text := FloatToStr(result); end; procedure TForm1.SpeedButton13Click(Sender: TObject); //按住SHIFT, 用鼠标点SpeedButton13, SpeedButton14(多选), 然后在属性面板双击onClick //以便2个SpeedButton共用一个OnClick事件, begin Flag1 := (Sender as TSpeedButton).Tag; num1 := StrToFloatDef(Edit1.Text, 0.00); Edit1.Text := '0'; end; procedure TForm1.SpeedButton15Click(Sender: TObject); //归零(复位) begin Flag := True; //。标记位 Flag1 := 1; //计算方法标志位 num1 := 0; num2 := 0; result := 0; Edit1.Text := '0'; end; procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char); //对窗口按键盘上的数字键时, 做输入操作数处理 begin case key of '1': SpeedButton1.Click; '2': SpeedButton2.Click; '3': SpeedButton3.Click; '4': SpeedButton4.Click; '5': SpeedButton5.Click; '6': SpeedButton6.Click; '7': SpeedButton7.Click; '8': SpeedButton8.Click; '9': SpeedButton9.Click; '0': SpeedButton10.Click; '.': SpeedButton11.Click; '+': SpeedButton13.Click; '-': SpeedButton14.Click; end; end; end.
采纳哦
6. Delphi语言中 文本文件中存入了一串数据,想让这些数据进行加减之类的运算,怎么写程序?
读出数据后先转成数值类型(用StrToInt/StrToFloat等函数即可),然后再进行加减运算,这2步都非常easy。
问题主要在于这些数据在文本文件中的存储形式,这决定了从文件中读写数据的难度。
最简单的一个存储文本数据的形式就是采用INI文件格式。如何使用请google,
基本用法如下:
Inifile:=Tinifile.create(FileName);
Inifile.ReadString(Section, Field, '0');
Inifile.WriteString(Section, Field, Value);
Inifile.free;
加入INI文件如下形式
FileName:
------------------------------
[Section]
Field=Value;
-----------------------------
7. 用delphi编写一个计算器,可几个数进行运算,两个数运算我会,大神多个数运算的怎么写,求救啊。
编写计算器程序,对于多个数运算,可以采取以下办法:
一是每次只进行两个数进行运算,然后将结果暂存,再进行下一次运算。
另一种是将先将运算式输入完毕,再进行分解后进行运算。这种方法要想做的好,需要进行语法解析。如果只是简单地加减乘除,不包含括号等,则相对简单一些。取巧的办法是调用 vbscript 的 eval 函数。
8. 用delphi7做一个计算器和用java编一个简单程序
java我还没学,delphi会一点,这是计算器的源代码,界面你就自己做了
procedure TForm1.FormCreate(Sender: TObject);
begin
button0.Click;
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
if point_flag=false then
begin
input_number(10);
point_flag:=true;
end;
end;
procedure TForm1.Button29Click(Sender: TObject);
begin
s_source_1:='0';
s_source_2:='0';
s_result:='0';
result:=0;
point_flag:=false;
operation_symbol:=0;
input_2:=false;
display_refresh();
end;
procedure TForm1.Button15Click(Sender: TObject);
begin
operation_over:=true;
source_1:=strtofloat(s_source_1);
if input_2 then
begin
source_2:=strtofloat(s_source_2);
end
else
begin
// source_2:=source_1;
// s_source_2:=floattostr(source_2);
end;
case operation_symbol of
0:
begin
result:=source_1;
display_refresh();
exit;
end;
1:
begin
result:=source_1+source_2;
display_refresh();
end;
2:
begin
result:=source_1-source_2;
display_refresh();
end;
3:
begin
result:=source_1 * source_2;
display_refresh();
end;
4:
begin
if source_2 = 0 then
begin
messagebox(form1.Handle,'0 不能做除数','错误!',0);
exit;
end;
result:=source_1 / source_2;
display_refresh();
end;
end;
input_2:=false;
source_1:=result;
s_source_1:=floattostr(result);
s_source_2:='0';
point_flag:=false;
end;
procedure TForm1.Button19Click(Sender: TObject);
begin
if result>=0 then
begin
operation_over:=true;
result:=sqrt(result);
display_refresh();
if input_2=true then
begin
source_2:=result;
s_source_2:='0';
input_2:=false;
end
else
begin
s_source_1:=floattostr(result);
end;
end
else
begin
messagebox(form1.Handle,'负数不能开根号','错误!',0);
end;
end;
procedure TForm1.Button30Click(Sender: TObject);
begin
if (operation_symbol >0) and (input_2 = true) then
begin
button15.Click;
end;
operation_symbol:=1;
// source_2:=0;
// s_source_2:='0';
point_flag:=false;
operation_over:=false;
end;
procedure TForm1.Button14Click(Sender: TObject);
begin
if (operation_symbol >0) and (input_2 = true) then
begin
button15.Click;
end;
operation_symbol:=2;
// source_2:=0;
// s_source_2:=floattostr(source_2);
point_flag:=false;
operation_over:=false;
end;
procedure TForm1.Button13Click(Sender: TObject);
begin
if (operation_symbol >0) and (input_2 = true) then
begin
button15.Click;
end;
operation_symbol:=3;
// source_2:=0;
// s_source_2:=floattostr(source_2);
point_flag:=false;
operation_over:=false;
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
if (operation_symbol >0) and (input_2 = true) then
begin
button15.Click;
end;
operation_symbol:=4;
// source_2:=0;
// s_source_2:=floattostr(source_2);
point_flag:=false;
operation_over:=false;
end;
procedure TForm1.Button24Click(Sender: TObject);
begin
if result 0 then
begin
operation_over:=true;
result:=1 / result;
display_refresh();
if input_2=true then
begin
source_2:=result;
s_source_2:='0';
input_2:=false;
end
else
begin
s_source_1:=floattostr(result);
end;
end
else
begin
messagebox(form1.Handle,'0 不能求倒数','错误!',0);
end;
end;
procedure TForm1.Button28Click(Sender: TObject);
begin
if input_2 = true then
begin
s_source_2:='0';
source_2:=0;
result:=0;
display_refresh();
end
else
begin
s_source_1:='0';
source_1:=0;
result:=0;
display_refresh();
end;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
result:=(-1)*result;
if input_2 then
begin
source_2:=result;
s_source_2:=floattostr(source_2);
end
else
begin
s_source_1:=floattostr(result);
end;
display_refresh();
end;
procedure TForm1.Button27Click(Sender: TObject);
begin
if input_2 = false then
begin
if length(s_source_1)>2 then
begin
delete(s_source_1,length(s_source_1),1);
result:=strtofloat(s_source_1);
display_refresh();
exit;
end;
if length(s_source_1)<=3 then
begin
result:=strtofloat(s_source_1);
if result <= 0 then
begin
s_source_1:='0';
end;
if result>0 then
begin
delete(s_source_1,length(s_source_1),1);
result:=strtofloat(s_source_1);
end;
display_refresh();
end;
end
else
begin
end;
end;
end.
实在不行再问我要完整的,我的邮箱345053709@qq.com