Delphi第一个入门程序——鼠标点击计数

实现的效果如下:


制作要点:

  添加一个按钮Button1和一个标签Label1,双击按钮进入编程界面在var  Form1: TForm1;下面一行加上  n:integer;//定义变量。

  然后在button1的实现代码处加入  label1.caption:=inttostr(n+1);   n:=n+1;  即可完成!

具体代码为:源代码下载

unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  n:integer;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.caption:=inttostr(n+1);
  n:=n+1;
end;

end.

程序美化:

  菜单栏Project——>Options——>Application选项卡,加入title和icon实现工具栏的现实以及程序的图标。

  菜单栏Project——>Options——>Version info选项卡,勾选第一个方框,在CompanyName中加入“Sunrising”,FileDescription中加入“今天你点了吗?”。实现修改程序公司,和程序名称。

可能会出现的问题:

  编译(F9)之后,在保存的项目目录下没有找到生成的程序,解决方法:菜单栏File——>Save all,再编译一次,就OK了。

  程序中出现红色错误,请看准你选用的组件,以及使用的属性方法,定义的变量就基本没有问题。

心得:

  用Delphi做的这个小东西,第一次感觉到编程的乐趣,即很有目的地做一件事,并且知道自己在做什么……

原文地址:https://www.cnblogs.com/imsoft/p/1stDelphi.html