-2

我想在 Delphi 表单上加减数字。我有两个按钮,一个标有“+”,一个标有“-”。

如果单击“+”按钮,显然需要在编辑框中显示的预先存在的值上添加一个数字。每点击一次“+”,编辑框中的数字就需要加1。如果单击“-”,则需要从编辑框中的值中减去 1。该值不能低于预先存在的值,在这种情况下为 35。

所以我的问题是,Delphi 中的编码如何查找这个,以及如何声明变量?

4

3 回答 3

2

在您的“-”按钮上。单击事件添加此代码

 procedure TForm1.Button1Click(Sender: TObject);
 var
  //declare all your variables here
  result : integer;
 begin
  result:=StrToInt(Edit1.text);
  if result=35 then
    exit
  else
    Edit1.text:=IntToStr(result-1);

 end;  

在你的“+”按钮上点击添加这个

 procedure TForm1.Button2Click(Sender: TObject);
 begin
   Edit1.text:=IntToStr(StrToInt(Edit1.Caption)+1);

 end;
于 2011-12-26T13:11:14.243 回答
0

将以下代码写入您的“+”按钮,但“-”并没有真正的不同:

Edit1.Caption := IntToStr(StrToInt(Edit1.Caption)+1);
于 2011-12-26T12:57:52.090 回答
0
procedure TForm1.btnIncrementClick(Sender: TObject);
var
  j: integer;
begin
  j := StrToInt(edit1.Text);
  inc(j);
  edit1.Text := IntToStr(j);
end;

procedure TForm1.btnDecrementClick(Sender: TObject);
var
  j: integer;
begin
  j := StrToInt(edit1.text);
  if J > 35 then
  begin
    dec(j);
    Edit1.Text := IntToStr(j);
  end;
end;
于 2011-12-29T01:37:46.427 回答