在问一次控件开发的有关属性的问题,真是郁闷! ( 积分: 10 )

  • 主题发起人 主题发起人 mill666
  • 开始时间 开始时间
M

mill666

Unregistered / Unconfirmed
GUEST, unregistred user!
前几天我过一次,根据各位大侠的指点,还是不行啊。不知道是不是俺写的不对。
俺现在写了一个最简单的例子:
unit Edit1;

interface

uses
SysUtils, Classes, Controls, StdCtrls,graphics,dialogs;

type

TMaskInputWay = ( tlInput,tlOutput,tlFix,tlHide,tlInOut);

TScreenInfo = class(TGraphicsObject)
private
FInputWay:TMaskInputWay;
procedure SetInputWay(value:TMaskInputWay);
public
constructor create(Owner:Tcomponent);
destructor Destroy; override;
published
property inputway:TMaskInputWay read Finputway write setinputway;
end;

TEdit1 = class(TEdit)
private

FScreenInfo:TScreenInfo;
procedure setcomponent(sender:Tobject);
procedure SetScreenInfo(value:TscreenInfo);
{ Private declarations }
protected
{ Protected declarations }
public
constructor create(Owner:Tcomponent);override;
destructor destroy;override;
{ Public declarations }
published
property screeninfo:TScreenInfo read FScreenInfo Write SetScreenInfo;
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Standard', [TEdit1]);
end;

{ TSreenInfo }

constructor TScreenInfo.create(Owner: Tcomponent);
begin
FInputWay:=tlInput;
end;

destructor TScreenInfo.Destroy;
begin
inherited;
end;

procedure TScreenInfo.SetInputWay(value: TMaskInputWay);
begin
Finputway:=value;
end;

{ TEdit1 }

constructor TEdit1.create(Owner: Tcomponent);
begin
inherited;
FScreenInfo:=TScreenInfo.create(self);
FScreenInfo.onchange:=setcomponent;
end;

destructor TEdit1.destroy;
begin
FScreenInfo.Free;
inherited;
end;

procedure TEdit1.setcomponent(sender:Tobject);
begin


showmessage('hello');

end;

procedure TEdit1.SetScreenInfo(value:TscreenInfo);
begin
FscreenInfo.Assign(value);

end;

end.
该控件的思路是:从Tedit类继承,增加了一个screeninfo类属性。screeninfo是一个Tscreeninfo的实例,下面有一个inputway属性。
然后安装控件。
新建一个项目,放置一个Tedit1的控件testedit,在object inspertor里面修改inputway的值,根据程序的思路,应当执行setcomponent过程,就是执行 showmessage('hello')这一句。
可是俺更改inputway的值的时候,并没有出现hello这么一个信息窗口啊。
不知道为什么??按理说我在程序里面已经设置了Fscreeninfo的onchange事件等于setcomponent了,应当出现hello这一信息窗才对啊。
 
前几天我过一次,根据各位大侠的指点,还是不行啊。不知道是不是俺写的不对。
俺现在写了一个最简单的例子:
unit Edit1;

interface

uses
SysUtils, Classes, Controls, StdCtrls,graphics,dialogs;

type

TMaskInputWay = ( tlInput,tlOutput,tlFix,tlHide,tlInOut);

TScreenInfo = class(TGraphicsObject)
private
FInputWay:TMaskInputWay;
procedure SetInputWay(value:TMaskInputWay);
public
constructor create(Owner:Tcomponent);
destructor Destroy; override;
published
property inputway:TMaskInputWay read Finputway write setinputway;
end;

TEdit1 = class(TEdit)
private

FScreenInfo:TScreenInfo;
procedure setcomponent(sender:Tobject);
procedure SetScreenInfo(value:TscreenInfo);
{ Private declarations }
protected
{ Protected declarations }
public
constructor create(Owner:Tcomponent);override;
destructor destroy;override;
{ Public declarations }
published
property screeninfo:TScreenInfo read FScreenInfo Write SetScreenInfo;
{ Published declarations }
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Standard', [TEdit1]);
end;

{ TSreenInfo }

constructor TScreenInfo.create(Owner: Tcomponent);
begin
FInputWay:=tlInput;
end;

destructor TScreenInfo.Destroy;
begin
inherited;
end;

procedure TScreenInfo.SetInputWay(value: TMaskInputWay);
begin
Finputway:=value;
end;

{ TEdit1 }

constructor TEdit1.create(Owner: Tcomponent);
begin
inherited;
FScreenInfo:=TScreenInfo.create(self);
FScreenInfo.onchange:=setcomponent;
end;

destructor TEdit1.destroy;
begin
FScreenInfo.Free;
inherited;
end;

procedure TEdit1.setcomponent(sender:Tobject);
begin


showmessage('hello');

end;

procedure TEdit1.SetScreenInfo(value:TscreenInfo);
begin
FscreenInfo.Assign(value);

end;

end.
该控件的思路是:从Tedit类继承,增加了一个screeninfo类属性。screeninfo是一个Tscreeninfo的实例,下面有一个inputway属性。
然后安装控件。
新建一个项目,放置一个Tedit1的控件testedit,在object inspertor里面修改inputway的值,根据程序的思路,应当执行setcomponent过程,就是执行 showmessage('hello')这一句。
可是俺更改inputway的值的时候,并没有出现hello这么一个信息窗口啊。
不知道为什么??按理说我在程序里面已经设置了Fscreeninfo的onchange事件等于setcomponent了,应当出现hello这一信息窗才对啊。
 
修改TScreenInfo.SetInputWay的写事件!

procedure TScreenInfo.SetInputWay(value: TMaskInputWay);
begin
if Finputway:=value then Exit;
Finputway:=value;
if Assigned(ONchange) then
ONchange(Self);
end;
 
后退
顶部