自定义属性与继承属性互斥(100分)

  • 主题发起人 xt2002xt
  • 开始时间
X

xt2002xt

Unregistered / Unconfirmed
GUEST, unregistred user!
我继承了一个Tcombobox,自己设计了一个ENTERTEXT的枚举属性{TRUE,FALSE},我想这个属性是TRUE的时候和老的一样,是FALSE的时候自动将STYLE属性改成csDropDownlist,这个怎么做到?
 
unit MyCMBOX;
interface
uses
SysUtils, Classes, Controls, StdCtrls;
Type
TMyCBBox = class(TComboBox)
private
FOldStyle : TComboBoxStyle;
FEnterText : Boolean;
procedure SetEnterText(const Value: Boolean);
protected
procedure SetStyle(Value: TComboBoxStyle);
override;
public
constructor Create(AOwner: TComponent);
override;
published
property EnterText : Boolean read FEnterText write SetEnterText;
end;

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

{ TMyCBBox }
constructor TMyCBBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FEnterText := Style <> csDropDownList;
end;

procedure TMyCBBox.SetEnterText(const Value: Boolean);
begin
if FEnterText <> Value then
begin
FEnterText := Value;
if FEnterText then
begin
Style := FOldStyle;
end
else
begin
if Style <> csDropDownList then
FOldStyle := Style;
Style := csDropDownList;
end;
end;
end;

procedure TMyCBBox.SetStyle(Value: TComboBoxStyle);
begin
inherited SetStyle(Value);
FEnterText := Style <> csDropDownList;
end;

end.
 
成功,谢谢!
 
顶部