你在FORM上拉三个控件,一个EDIT,两个BUTTON。分别双击两个BUTTON。然后在代码编辑器里面,把代码换成下面的。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
variable:Integer;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Inc(variable);
Edit1.Text:= IntToStr(variable);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Inc(variable,3);
Edit1.Text:= IntToStr(variable);
end;
end.
F9运行就可以测试到效果了。