标题:求助delphi
只看楼主
sheng443
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2008-7-1
 问题点数:0 回复次数:2 
求助delphi
请问如何写组件只单击一次有效,我是菜鸟,想写一个计算器,大家帮我看看(大家不好意思,可能是我没说明原因,我是想请问,当按了两个小数点的时候让它在eidt中显示一个),代码如下:unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    SpeedButton12: TSpeedButton;
    SpeedButton13: TSpeedButton;
    SpeedButton14: TSpeedButton;
    SpeedButton15: TSpeedButton;
    SpeedButton16: TSpeedButton;
    SpeedButton17: TSpeedButton;
    SpeedButton18: TSpeedButton;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure SpeedButton7Click(Sender: TObject);
    procedure SpeedButton8Click(Sender: TObject);
    procedure SpeedButton9Click(Sender: TObject);
    procedure SpeedButton10Click(Sender: TObject);
    procedure SpeedButton11Click(Sender: TObject);
    procedure SpeedButton13Click(Sender: TObject);
    procedure SpeedButton14Click(Sender: TObject);
    procedure SpeedButton15Click(Sender: TObject);
    procedure SpeedButton16Click(Sender: TObject);
    procedure SpeedButton17Click(Sender: TObject);
    procedure SpeedButton18Click(Sender: TObject);
    procedure SpeedButton12Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  a,c:Double;
  b:integer;

implementation

{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
edit1.Text:=edit1.text+'1';
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
edit1.Text:=edit1.text+'2';
end;

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
edit1.Text:=edit1.text+'3';
end;

procedure TForm1.SpeedButton4Click(Sender: TObject);
begin
edit1.Text:=edit1.text+'4';
end;

procedure TForm1.SpeedButton5Click(Sender: TObject);
begin
edit1.Text:=edit1.text+'5';
end;

procedure TForm1.SpeedButton6Click(Sender: TObject);
begin
edit1.Text:=edit1.text+'6';
end;

procedure TForm1.SpeedButton7Click(Sender: TObject);
begin
edit1.Text:=edit1.text+'7';
end;

procedure TForm1.SpeedButton8Click(Sender: TObject);
begin
edit1.Text:=edit1.text+'8';
end;

procedure TForm1.SpeedButton9Click(Sender: TObject);
begin
 edit1.Text:=edit1.text+'9';
end;

procedure TForm1.SpeedButton10Click(Sender: TObject);
begin
edit1.Text:=edit1.text+'0';
end;

procedure TForm1.SpeedButton11Click(Sender: TObject);
begin
edit1.Text:=edit1.Text+'.';
end;

procedure TForm1.SpeedButton13Click(Sender: TObject);

begin
  b:=1;
  a:=strtofloat(edit1.Text);
  edit1.Clear;

end;

procedure TForm1.SpeedButton14Click(Sender: TObject);
begin
b:=2;
a:=strtofloat(edit1.Text);
  edit1.Clear;
end;

procedure TForm1.SpeedButton15Click(Sender: TObject);
begin
b:=3;
a:=strtofloat(edit1.Text);
  edit1.Clear;
end;

procedure TForm1.SpeedButton16Click(Sender: TObject);
begin
b:=4;
a:=strtofloat(edit1.Text);
  edit1.Clear;
end;

procedure TForm1.SpeedButton17Click(Sender: TObject);
begin
edit1.clear;
end;

procedure TForm1.SpeedButton18Click(Sender: TObject);
begin
close;
end;

procedure TForm1.SpeedButton12Click(Sender: TObject);
begin
case b of
1:c:=a+strtofloat(edit1.text);
2:c:=a-strtofloat(edit1.text);
3:c:=a*strtofloat(edit1.text);
4:c:=a/strtofloat(edit1.text);
 end;
 edit1.text:=floattostr(c);
end;

end.

[[it] 本帖最后由 sheng443 于 2008-9-13 01:59 编辑 [/it]]
搜索更多相关主题的帖子: delphi 
2008-09-12 18:14
fengyun1989
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2008-8-4
得分:0 
有什么问题?代码好像没什么问题呀,我觉得那个好像是 var  a:string   c:real
。不过,我也是菜鸟,我觉得你应该把那个编译错误的信息也复制上来,这样,大家才能更好的帮你!
2008-09-12 23:27
nongen
Rank: 5Rank: 5
来 自:网络
等 级:贵宾
威 望:17
帖 子:322
专家分:0
注 册:2006-11-25
得分:0 
在你按+-*/时,应该给出一个变量用于存储当前edit1中的数字,然后清空edit1.text=0
还有,
当edit1是0的时候,需要判断,你按的是哪个键,如果按的是数字,那就直接变为数字,
如果按的是点,则不变,再输入时变成0.XXX

昨天不是我的,明天不是你的,今天却是我们的。
http://www.
2008-09-13 00:58



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-232931-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015398 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved