一个 form1 窗口,上面只有一个 Edit1 和十五个 Button1-15 ,分别是计算器的1-10和加/减/乘/除/等/,做了一半就迷糊了,高手请说一下愿代码,旁边加上注释好吗,嘻嘻~~~我真是什么都不懂.谢谢了。我把做了一半的原代码写出来,高手请继续,要是我的是错的,请附完整代码,再次感谢.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, Buttons, 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;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(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);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
button1,button2,button3,button4,button5,button6,button7,button8,button9,button10:string;
s:string;
m:integer;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:='1'
end;procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:='2'
end;procedure TForm1.Button3Click(Sender: TObject);
begin
edit1.Text:='3';
end;procedure TForm1.Button4Click(Sender: TObject);
begin
edit1.Text:='4';
end;procedure TForm1.Button5Click(Sender: TObject);
begin
edit1.Text:='5';
end;procedure TForm1.Button6Click(Sender: TObject);
begin
edit1.Text:='6';
end;procedure TForm1.Button7Click(Sender: TObject);
begin
edit1.Text:='7';
end;procedure TForm1.Button8Click(Sender: TObject);
begin
edit1.Text:='8';
end;procedure TForm1.Button9Click(Sender: TObject);
begin
edit1.Text:='9';
end;procedure TForm1.Button10Click(Sender: TObject);
begin
edit1.Text:='10';
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, Buttons, 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;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(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);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
button1,button2,button3,button4,button5,button6,button7,button8,button9,button10:string;
s:string;
m:integer;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:='1'
end;procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:='2'
end;procedure TForm1.Button3Click(Sender: TObject);
begin
edit1.Text:='3';
end;procedure TForm1.Button4Click(Sender: TObject);
begin
edit1.Text:='4';
end;procedure TForm1.Button5Click(Sender: TObject);
begin
edit1.Text:='5';
end;procedure TForm1.Button6Click(Sender: TObject);
begin
edit1.Text:='6';
end;procedure TForm1.Button7Click(Sender: TObject);
begin
edit1.Text:='7';
end;procedure TForm1.Button8Click(Sender: TObject);
begin
edit1.Text:='8';
end;procedure TForm1.Button9Click(Sender: TObject);
begin
edit1.Text:='9';
end;procedure TForm1.Button10Click(Sender: TObject);
begin
edit1.Text:='10';
end;end.
解决方案 »
- 如何用delphi7.0连接显示excel表中的内容
- 用adodataset连接数据库,如何删除选中的记录?
- 怎样调用全局变量?在线等待?
- 用Delphi做PDA的后台,大概用什么样的技术
- 热烈欢迎大家讨论一下《关于数据传输的问题》?
- Delphi与SQL怎么一起用啊,散分!!
- 我是不是该.....?
- 在Delphi中怎么使用ADO的Recordset?我在VB中用它挺好用,最好给个例子
- delphi字符串定义问题!希望高手进来帮帮忙!!
- 如何去掉调用Dll在任务栏产生的图标
- 升4个三角,庆祝散200分。吃饭回来结贴。
- 怎么做才能用DBGRID2显示DBGRID1的对应东西就是主从了,比如DBGIRD1上号码的的001内容在DBGRID2上全部显示出来
再利用edit作为输出值控件,运算符用button.在运算符‘=’中加入代码就可以了;
就点拨到这儿吧,作题还是要靠自己的聪明脑瓜去领悟吆。
象 按键 1 的代码怎么些?就是怎么样能输出到那个 Edit 里?
将一个包括多重扩号的四则运算代数式转换为浮点数,经典算法是用运算符后置法,再用栈原理计算。小苦想到了一种新颖的算法,用嵌套调用和递归也可以把结果算出来。小苦写成动态链接库TxtToF.dll,VB,Delphi,C++Builder,Visual C++,Java等可以调用。
源代码如下:
//动态连接库TxtToF.dll
library TxtToF; uses
SysUtils;
//删除字符串S中的子串SubStr
function DeleteSubStr(S, SubStr: String): String;
begin
while Pos(SubStr, S) <> 0 do
Delete(S, Pos(SubStr, S), Length(SubStr));
Result := S;
end; //删除字符串中的所有扩号
function DeleteK(S: String): String;
begin
S := DeleteSubStr(S, '(');
S := DeleteSubStr(S, ')');
Result := S;
end; //返回字符串代数式的第一个运算符的整形序号
function GetOpIndex(S: String): Integer;
var
iAdd, iSub, iMu, iDiv: Integer;
begin
iAdd := Pos('+', S);
iSub := Pos('-', S);
iMu := Pos('*', S);
iDiv := Pos('/', S); if iAdd = 0 then iAdd := 1000;
if iSub = 0 then iSub := 1000;
if iMu = 0 then iMu := 1000;
if iDiv = 0 then iDiv := 1000; if (iAdd < iSub) and (iAdd < iMu) and
(iAdd < iDiv) then Result := iAdd else
if (iSub < iAdd) and (iSub < iMu) and
(iSub < iDiv) then Result := iSub else
if (iMu < iAdd) and (iMu < iSub) and
(iMu < iDiv) then Result := iMu else
if (iDiv < iAdd) and (iDiv < iSub) and
(iDiv < iMu) then Result := iDiv
else
Result := 0;
end; //消除一个浮点数的前面的多重负号,如"__2"返回"2","___2"返回"_2"
function DeleteMinus(S: String): String;
var
bMinus: Boolean;
begin
bMinus := False;
while S[1] = '_' do
begin
Delete(S, 1, 1);
bMinus := not(bMinus);
end;
if bMinus then Result := '_' + S
else Result := S;
end; //计算单运算符的代数式,返回浮点数字符串,负号为"_"
function SingleCal(S: String): String;
var
strTemp, strResult: String;
fLeft, fRight: Double;
i, iOpIndex: Integer;
begin
if S[1] = '-' then S[1] := '_'; iOpIndex := GetOpIndex(S); //要是没有运算符的话,S就是结果
if (iOpIndex = 0) then
begin
Result := S;
exit;
end; strTemp := ' ';
for i := 0 to iOpIndex - 1 do
strTemp[i] := S[i];
strTemp := Trim(strTemp);
strTemp := DeleteMinus(strTemp);
if strTemp[1] = '_' then
begin
Delete(strTemp, 1, 1);
fLeft := - StrToFloat(strTemp);
end else
fLeft := StrToFloat(strTemp); strTemp := ' ';
for i := iOpIndex + 1 to Length(S) do
strTemp[i] := S[i];
strTemp := Trim(strTemp);
strTemp := DeleteMinus(strTemp);
if strTemp[1] = '_' then
begin
Delete(strTemp, 1, 1);
fRight := - StrToFloat(strTemp);
end else
fRight := StrToFloat(strTemp); if S[iOpIndex] = '+' then
strResult := FloatToStr(fLeft + fRight)
else if S[iOpIndex] = '-' then
strResult := FloatToStr(fLeft - fRight)
else if S[iOpIndex] = '*' then
strResult := FloatToStr(fLeft * fRight)
else if S[iOpIndex] = '/' then
strResult := FloatToStr(fLeft / fRight); if strResult[1] = '-' then
strResult[1] := '_'; Result := strResult;
end; //计算只有加号或减号的多运算符代数式,返回浮点数字符串,负号为"_"
function AddSubCal(S: String): String;
var
strTemp: String;
iOpIndex, iLeft, iRight, i: Integer;
begin
if S[1] = '-' then S[1] := '_'; //要是没有运算符号,S就是结果
iOpIndex := GetOpIndex(S);
if (iOpIndex = 0) then
begin
Result := SingleCal(S);
exit;
end; //计算第一条单运算符式子的左浮点数起始位置iLeft
iLeft := iOpIndex - 1;
while (S[iLeft] <> '+') and (S[iLeft] <> '-') and
(S[iLeft] <> '*') and (S[iLeft] <> '/') and (S[iLeft] <> '') do
iLeft := iLeft - 1;
iLeft := iLeft + 1;
iRight := iOpIndex + 1;
while (S[iRight] <> '+') and (S[iRight] <> '-') and
(S[iRight] <> '*') and (S[iRight] <> '/') and (S[iRight] <> '') do
iRight := iRight + 1;
iRight := iRight - 1; strTemp := ' ';
for i := iLeft to iRight do
strTemp[i] := S[i];
strTemp := Trim(strTemp); Delete(S, iLeft, iRight-iLeft+1);
Insert(SingleCal(strTemp), S, iLeft); //递归调用AddSubCal
//每调用一次AddSubCal,消除式中的一个运算符,知道没有运算符为止
Result := AddSubCal(S);
end; //计算无扩号的多运算符代数式,返回浮点数字符串,负号为"_"
function NoKCal(S: String): String;
var
strTemp: String;
iOpIndex, iMu, iDiv, iLeft, iRight, i: Integer;
begin
if S[1] = '-' then S[1] := '_'; iOpIndex := GetOpIndex(S);
//要是没有运算符号,S就是结果
if (iOpIndex = 0) then
begin
Result := AddSubCal(S);
exit;
end; //将负数的负号转为'_'
if (iOpIndex = 1) and (S[1] = '-') then
S[1] := '_'; //------------首先考虑运算符等级高的乘号和除号---------------
iMu := Pos('*', S);
iDiv := Pos('/', S); if (iMu <> 0) or (iDiv <> 0) then
begin
//乘法运算
if ((iMu < iDiv) and (iMu <> 0)) or ((iMu <> 0) and (iDiv = 0)) then
begin
iLeft := iMu - 1;
while (S[iLeft] <> '+') and (S[iLeft] <> '-') and
(S[iLeft] <> '*') and (S[iLeft] <> '/') and (S[iLeft] <> '') do
iLeft := iLeft - 1;
iLeft := iLeft + 1; iRight := iMu + 1;
while (S[iRight] <> '+') and (S[iRight] <> '-') and
(S[iRight] <> '*') and (S[iRight] <> '/') and (S[iRight] <> '') do
iRight := iRight + 1;
iRight := iRight - 1; strTemp := ' ';
for i := iLeft to iRight do
strTemp[i] := S[i];
strTemp := Trim(strTemp); Delete(S, iLeft, iRight-iLeft+1);
Insert(SingleCal(strTemp), S, iLeft); //递归调用NoKCal
Result := NoKCal(S);
exit;
end; //除法运算
if (iDiv < iMu) and (iDiv <> 0) or ((iDiv <> 0) and (iMu = 0)) then
begin
iLeft := iDiv - 1;
while (S[iLeft] <> '+') and (S[iLeft] <> '-') and
(S[iLeft] <> '*') and (S[iLeft] <> '/') and (S[iLeft] <> '') do
iLeft := iLeft - 1;
iLeft := iLeft + 1; iRight := iDiv + 1;
while (S[iRight] <> '+') and (S[iRight] <> '-') and
(S[iRight] <> '*') and (S[iRight] <> '/') and (S[iRight] <> '') do
iRight := iRight + 1;
iRight := iRight - 1; strTemp := ' ';
for i := iLeft to iRight do
strTemp[i] := S[i];
strTemp := Trim(strTemp); Delete(S, iLeft, iRight-iLeft+1);
Insert(SingleCal(strTemp), S, iLeft); //递归调用NoKCal,直到没有*号和/号为止
Result := NoKCal(S);
exit;
end;
end else
//---------------------------------------------------------------
Result := AddSubCal(S);//S只剩下加号或减号了
end; //计算复杂的代数式字符串,返回浮点数字符串,负号为"_"
function Cal(S: String): String;
var
strTemp, strOp: String;
iLeftK, iRightK, iTemp, i: Integer;
begin
//删除空格
S := DeleteSubStr(S, ' '); //要是式子为不带扩号的简单运算式的话
if Pos('(', S) = 0 then
begin
Result := NoKCal(S);
exit;
end; // 计算出式中最后一个左扩号的位置iLeftK,并把它前面的字符串和它都删除
strTemp := S;
iTemp := Pos('(', strTemp);
iLeftK := - iTemp;
while iTemp <> 0 do
begin
iLeftK := iLeftK + iTemp;
iTemp := Pos('(', strTemp);
Delete(strTemp, 1, iTemp);
end; //strOp是包含左、右扩号的多运算符符式,把扩号删除后交由NoKCal计算
strOp := ' ';
iRightK := Pos(')', strTemp);
for i := 0 to iRightK do
strOp[i] := strTemp[i];
strOp := '(' + Trim(strOp); //删除多运算符式,用其计算结果代替
Delete(S, iLeftK, iRightK+1);
strOp := DeleteK(strOp);//删除扩号
Insert(NoKCal(strOp), S, iLeftK); //递归调用Cal
//每调用一次Cal,式中就计算出式中优先级最高的一对扩号中
//多运算符代数式的值,知道没有扩号为止
Result := Cal(S);
end; //将Cal算出的结果转化为双精度浮点数
//此函数符合stdcall约定
function TxtToFloat(S: String): Double; stdcall;
begin
S := Cal(S);
S := DeleteMinus(S);
if S[1] = '_' then
begin
Delete(S, 1, 1);
Result := - StrToFloat(S);
end else
Result := StrToFloat(S);
end; //引出函数
exports
TxtToFloat; begin
end.
procedure TForm1.Button1Click(Sender: TObject);
var
StartupInfo:TStartupInfo;
ProcessInfo:TProcessInformation;
begin
// 初始化工作
FillChar(StartupInfo,Sizeof(StartupInfo),#0) ;
StartupInfo.cb := Sizeof(StartupInfo);
StartupInfo.dwFlags :=STARTF_USESHOWWINDOW;
CreateProcess(nil,
'Calc', // 运行计算器
nil ,
nil ,
false ,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS,
nil ,
nil ,
StartupInfo,
ProcessInfo) ;
END;
var
Form1: TForm1;
button1,button2,button3,button4,button5,button6,button7,button8,button9,button10:string;
s:string;
m:integer;
begin
if sender is tbutton then edit1.text:=edit1.text+sender as tbutton.caption;
end;然后每个按牛调用上面的就可以了很简单问题,fastreport中关于直接打印表格的几点问题(无未解帖记录)UP有分,总分200分,请各位做过的去帮帮忙
http://expert.csdn.net/Expert/topic/1553/1553122.xml?temp=.7381403