delphi向窗体添加属性

声明中private和public

代码
unit Unit1;

interface

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

type
  TForm1 
= class(TForm)
    Button1: TButton;
    
procedure Button1Click(Sender: TObject);
    
procedure FormClick(Sender: TObject);
  
private
    
{ Private declarations }
    FClicks: Integer;              
//自定义的字段
    
procedure SetClicks(const Value: Integer);
  
public
    
property Clicks: Integer read FClicks write SetClicks; //设置属性
    
{ Public declarations }
  
end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
procedure TForm1.SetClicks(const Value: Integer);
begin
  FClicks :
= Value;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 
with TForm1.Create(self) do
  Show;
end;

procedure TForm1.FormClick(Sender: TObject);
begin
  Inc (FClicks);
  Caption :
= 'Clicks: ' + IntToStr (FClicks);
end;

end.


 

posted @ 2010-02-22 11:34  doze  阅读(255)  评论(0)    收藏  举报