在对象监视器中修改的自制组件属性无效?(30分小问题) ( 积分: 30 )

  • 主题发起人 主题发起人 nopo
  • 开始时间 开始时间
N

nopo

Unregistered / Unconfirmed
GUEST, unregistred user!
小菜按照教科书上所写,编了一个TCloseButton组件,在published下加了CanClose:Boolean这个新属性,这个属性在对象监视器中可以看到,也可以修改,但是修改后的结果不能反馈到程序中…… 原因不知何在…… 附组件源代码……

unit CloseButton;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls,Forms;

type
TCloseQueryEvent = procedure(Sender:Tobject;Var CanClose:Boolean) of Object;
TCloseButton = class(TButton)
private
FCanClose:Boolean;
FOnCloseQuery:TCloseQueryEvent;
Fnum:integer;
{ Private declarations }
protected
{ Protected declarations }

procedure CloseForm;virtual;
procedure click;override;
procedure CloseQuery;dynamic;

public
{ Public declarations }
published
{ Published declarations }
property CanClose:Boolean read FCanClose write FCanClose default true ;
property num:integer read Fnum write Fnum default 100;

property OnCloseQuery:TCloseQueryEvent read Fonclosequery write FONCloseQuery;

end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TCloseButton]);
end;

procedure TcloseButton.CloseForm;
begin
if FCanClose then (owner as TForm).Close;
end;

procedure TCloseButton.click;
begin
inherited click;
CloseQuery;
CloseForm;
end;

procedure TCloseButton.CloseQuery;
begin
if assigned(FOnCloseQuery) then
FOnCloseQuery(self,FCanClose);
end;

end.
 
小菜按照教科书上所写,编了一个TCloseButton组件,在published下加了CanClose:Boolean这个新属性,这个属性在对象监视器中可以看到,也可以修改,但是修改后的结果不能反馈到程序中…… 原因不知何在…… 附组件源代码……

unit CloseButton;

interface

uses
Windows, Messages, SysUtils, Classes, Controls, StdCtrls,Forms;

type
TCloseQueryEvent = procedure(Sender:Tobject;Var CanClose:Boolean) of Object;
TCloseButton = class(TButton)
private
FCanClose:Boolean;
FOnCloseQuery:TCloseQueryEvent;
Fnum:integer;
{ Private declarations }
protected
{ Protected declarations }

procedure CloseForm;virtual;
procedure click;override;
procedure CloseQuery;dynamic;

public
{ Public declarations }
published
{ Published declarations }
property CanClose:Boolean read FCanClose write FCanClose default true ;
property num:integer read Fnum write Fnum default 100;

property OnCloseQuery:TCloseQueryEvent read Fonclosequery write FONCloseQuery;

end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TCloseButton]);
end;

procedure TcloseButton.CloseForm;
begin
if FCanClose then (owner as TForm).Close;
end;

procedure TCloseButton.click;
begin
inherited click;
CloseQuery;
CloseForm;
end;

procedure TCloseButton.CloseQuery;
begin
if assigned(FOnCloseQuery) then
FOnCloseQuery(self,FCanClose);
end;

end.
 
后退
顶部