A
awfigsk
Unregistered / Unconfirmed
GUEST, unregistred user!
像下面这个组件的代码(部分):
type
TMdFontCombo = class(TComboBox)
private
{ Private declarations }
FChangeFormFont:Boolean;
procedure SetChangeFormFont(const Value:Boolean);
protected
{ Protected declarations }
public
{ Public declarations }
...
procedure Change;override;
published
{ Published declarations }
...
property ChangeFormFont:Boolean
read FChangeFormFont write SetChangeFormFont default True;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyComponent', [TMdFontCombo]);
end;
{ TMdFontCombo }
constructor TMdFontCombo.Create(AOwner: TComponent);
begin
inherited;
Style:=csDropDownList;
FChangeFormFont:=True;
end;
procedure TMdFontCombo.SetChangeFormFont(const Value: Boolean);
begin
FChangeFormFont:=Value;
if FChangeFormFont then //refresh font
Change;
end;
procedure TMdFontCombo.Change;
begin
//assign the font to the owner form
if FChangeFormFont and Assigned(Owner) and (Owner is TForm) then
TForm(Owner).Font.Name:=Text;
inherited;
end;
end.
上面的change方法对应着组件的onchange事件,当在使用该组件时,代码如下:
type
TForm1 = class(TForm)
Label1: TLabel;
Memo1: TMemo;
MdFontCombo1: TMdFontCombo;
procedure MdFontCombo1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.MdFontCombo1Change(Sender: TObject);
begin
end;
我不明白的是:我在使用组件时,在其change事件中并无代码,也无inherited关键字,为何在改变MdFontCombo1时,怎么会执行组件中的change方法的代码?而当[red]TForm1.MdFontCombo1Change中有代码时,则也会先执行TMdFontCombo.Change;中的代码,再执行程序中TForm1.MdFontCombo1Change代码?[/red]
type
TMdFontCombo = class(TComboBox)
private
{ Private declarations }
FChangeFormFont:Boolean;
procedure SetChangeFormFont(const Value:Boolean);
protected
{ Protected declarations }
public
{ Public declarations }
...
procedure Change;override;
published
{ Published declarations }
...
property ChangeFormFont:Boolean
read FChangeFormFont write SetChangeFormFont default True;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('MyComponent', [TMdFontCombo]);
end;
{ TMdFontCombo }
constructor TMdFontCombo.Create(AOwner: TComponent);
begin
inherited;
Style:=csDropDownList;
FChangeFormFont:=True;
end;
procedure TMdFontCombo.SetChangeFormFont(const Value: Boolean);
begin
FChangeFormFont:=Value;
if FChangeFormFont then //refresh font
Change;
end;
procedure TMdFontCombo.Change;
begin
//assign the font to the owner form
if FChangeFormFont and Assigned(Owner) and (Owner is TForm) then
TForm(Owner).Font.Name:=Text;
inherited;
end;
end.
上面的change方法对应着组件的onchange事件,当在使用该组件时,代码如下:
type
TForm1 = class(TForm)
Label1: TLabel;
Memo1: TMemo;
MdFontCombo1: TMdFontCombo;
procedure MdFontCombo1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.MdFontCombo1Change(Sender: TObject);
begin
end;
我不明白的是:我在使用组件时,在其change事件中并无代码,也无inherited关键字,为何在改变MdFontCombo1时,怎么会执行组件中的change方法的代码?而当[red]TForm1.MdFontCombo1Change中有代码时,则也会先执行TMdFontCombo.Change;中的代码,再执行程序中TForm1.MdFontCombo1Change代码?[/red]