如何在设计模式下将两个属性设置为一个节点并更改标题?
How to set two properties as a node and change the caption in design mode?
我正在尝试创建一个名为 CheckEdit
的新组件,如下所示:
unit UnitName;
interface
uses
System.Classes, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Controls;
type
TCheckEdit = class (TCustomControl)
private
FCheckBox : TCheckBox;
FEdit : TEdit;
FEnableCaption: TCaption;
FDisbleCaption: TCaption;
procedure SetIsActive(const Value: Boolean);
function GetIsActive : Boolean;
procedure ChBoxOnClick (Sender : TObject);
procedure SetDisbleCaption(const Value: TCaption);
procedure SetEnableCaption(const Value: TCaption);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property IsActive : Boolean read GetIsActive write SetIsActive default False;
property EnableCaption : TCaption read FEnableCaption write SetEnableCaption;
property DisbleCaption : TCaption read FDisbleCaption write SetDisbleCaption;
property OnClick;
end;
procedure register;
implementation
procedure register;
begin
RegisterComponents('Standard', [TCheckEdit]);
end;
{ TCheckEdit }
procedure TCheckEdit.ChBoxOnClick(Sender: TObject);
begin
if FCheckBox.Checked then
IsActive := True
else
IsActive:= False;
end;
constructor TCheckEdit.Create(AOwner: TComponent);
begin
inherited;
FCheckBox := TCheckBox.Create(Self);
FCheckBox.Parent := Self;
FCheckBox.Align := alTop;
FCheckBox.Caption := Self.Name;
FCheckBox.OnClick := ChBoxOnClick;
FDisbleCaption := 'Disabled';
FEnableCaption := 'Enabled';
FCheckBox.Caption := FDisbleCaption;
FEdit := TEdit.Create(Self);
FEdit.Parent := Self;
FEdit.Align := alTop;
FEdit.Enabled := False;
Self.Height := 40;
Self.Width := 185;
Self.AutoSize := True;
end;
destructor TCheckEdit.Destroy;
begin
FEdit.Free;
FCheckBox.Free;
inherited;
end;
function TCheckEdit.GetIsActive: Boolean;
begin
if FCheckBox.Checked then
Result := True
else
Result := False;
end;
procedure TCheckEdit.SetDisbleCaption(const Value: TCaption);
begin
FDisbleCaption := Value;
end;
procedure TCheckEdit.SetEnableCaption(const Value: TCaption);
begin
FEnableCaption := Value;
end;
procedure TCheckEdit.SetIsActive(const Value: Boolean);
begin
FCheckBox.Checked := Value;
case Value of
True :
begin
FEdit.Enabled := True;
FCheckBox.Caption := FEnableCaption;
end;
False :
begin
FEdit.Enabled := False;
FCheckBox.Caption := FDisbleCaption;
end;
end;
end;
end.
一切正常,但我想在一个节点中制作 EnableCaption
和 DisableCaption
,因为 TToggleSwitch
有 StateCaptions
属性,当我更改标题也会在 CheckBox
中更改它。
我尝试在 SetEnableCaption
和 SetDisbleCaption
过程中调用 Invalidate;
,但这不起作用。
我该怎么做?
老实说,一开始我不想回答这个问题,因为你已经在 SO
上的一个问题中找到了答案
第一个class准确的说是TPersistent
暴露了TNCRSpeedButton
中的Glyph坐标。
我写这篇文章是因为我说过 我希望你能从中受益。 我可以看出你没有。
这就是您的问题解决方案,非常欢迎您询问有关它是如何实施的任何问题。
unit UnitName;;
interface
uses
System.Classes, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Controls;
type
TCheckEditCaptions = class(TPersistent)
private
FDisableCaption: TCaption;
FEnableCaption: TCaption;
FOnChange: TNotifyEvent;
function GetDisableCaption: TCaption;
function GetEnableCaption: TCaption;
procedure SetDisableCaption(const Value: TCaption);
procedure SetEnableCaption(const Value: TCaption);
public
procedure Assign(aValue: TPersistent); override;
published
property EnableCaption: TCaption read GetEnableCaption write SetEnableCaption;
property DisableCaption: TCaption read GetDisableCaption write SetDisableCaption;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
TCheckEdit = class (TCustomControl)
private
FCheckBox : TCheckBox;
FEdit : TEdit;
FCheckEditCaptions: TCheckEditCaptions;
procedure SetIsActive(const Value: Boolean);
function GetIsActive : Boolean;
procedure ChBoxOnClick (Sender : TObject);
procedure CheckEditCaptionsChanged(Sender : TObject);
procedure SetCheckEditCaptions(const Value: TCheckEditCaptions);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property IsActive : Boolean read GetIsActive write SetIsActive default False;
property CheckEditCaptions : TCheckEditCaptions read FCheckEditCaptions write SetCheckEditCaptions;
property OnClick;
end;
procedure register;
implementation
procedure register;
begin
RegisterComponents('Samples', [TCheckEdit]);
end;
{ TCheckEdit }
procedure TCheckEdit.ChBoxOnClick(Sender: TObject);
begin
IsActive := FCheckBox.Checked;
end;
procedure TCheckEdit.CheckEditCaptionsChanged(Sender: TObject);
begin
SetIsActive(GetIsActive);
end;
constructor TCheckEdit.Create(AOwner: TComponent);
begin
inherited;
FCheckBox := TCheckBox.Create(Self);
FCheckBox.Parent := Self;
FCheckBox.Align := alTop;
FCheckBox.OnClick := ChBoxOnClick;
FCheckEditCaptions := TCheckEditCaptions.Create;
FCheckEditCaptions.FDisableCaption := 'Disabled';
FCheckEditCaptions.FEnableCaption := 'Enabled';
FCheckEditCaptions.OnChange := CheckEditCaptionsChanged;
FCheckBox.Caption := CheckEditCaptions.DisableCaption;
FEdit := TEdit.Create(Self);
FEdit.Parent := Self;
FEdit.Align := alTop;
FEdit.Enabled := False;
Self.Height := 40;
Self.Width := 185;
Self.AutoSize := True;
end;
destructor TCheckEdit.Destroy;
begin
FEdit.Free;
FCheckBox.Free;
FCheckEditCaptions.Free;
inherited;
end;
function TCheckEdit.GetIsActive: Boolean;
begin
Result := FCheckBox.Checked ;
end;
procedure TCheckEdit.SetCheckEditCaptions(const Value: TCheckEditCaptions);
begin
FCheckEditCaptions.Assign(Value);
end;
procedure TCheckEdit.SetIsActive(const Value: Boolean);
begin
FCheckBox.Checked := Value;
FEdit.Enabled := Value;
if Value then
FCheckBox.Caption := CheckEditCaptions.EnableCaption
else
FCheckBox.Caption := CheckEditCaptions.DisableCaption;
end;
{ TCheckEditCaptions }
procedure TCheckEditCaptions.Assign(aValue: TPersistent);
begin
if aValue is TCheckEditCaptions then begin
FEnableCaption := TCheckEditCaptions(aValue).FEnableCaption;
FEnableCaption := TCheckEditCaptions(aValue).FDisableCaption;
if Assigned(FOnChange) then
FOnChange(self);
end else
inherited;
end;
function TCheckEditCaptions.GetDisableCaption: TCaption;
begin
result := FDisableCaption;
end;
function TCheckEditCaptions.GetEnableCaption: TCaption;
begin
result := FEnableCaption;
end;
procedure TCheckEditCaptions.SetDisableCaption(const Value: TCaption);
begin
FDisableCaption := Value;
if Assigned(FOnChange) then
FOnChange(self);
end;
procedure TCheckEditCaptions.SetEnableCaption(const Value: TCaption);
begin
FEnableCaption := Value;
if Assigned(FOnChange) then
FOnChange(self);
end;
end.
我正在尝试创建一个名为 CheckEdit
的新组件,如下所示:
unit UnitName;
interface
uses
System.Classes, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Controls;
type
TCheckEdit = class (TCustomControl)
private
FCheckBox : TCheckBox;
FEdit : TEdit;
FEnableCaption: TCaption;
FDisbleCaption: TCaption;
procedure SetIsActive(const Value: Boolean);
function GetIsActive : Boolean;
procedure ChBoxOnClick (Sender : TObject);
procedure SetDisbleCaption(const Value: TCaption);
procedure SetEnableCaption(const Value: TCaption);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property IsActive : Boolean read GetIsActive write SetIsActive default False;
property EnableCaption : TCaption read FEnableCaption write SetEnableCaption;
property DisbleCaption : TCaption read FDisbleCaption write SetDisbleCaption;
property OnClick;
end;
procedure register;
implementation
procedure register;
begin
RegisterComponents('Standard', [TCheckEdit]);
end;
{ TCheckEdit }
procedure TCheckEdit.ChBoxOnClick(Sender: TObject);
begin
if FCheckBox.Checked then
IsActive := True
else
IsActive:= False;
end;
constructor TCheckEdit.Create(AOwner: TComponent);
begin
inherited;
FCheckBox := TCheckBox.Create(Self);
FCheckBox.Parent := Self;
FCheckBox.Align := alTop;
FCheckBox.Caption := Self.Name;
FCheckBox.OnClick := ChBoxOnClick;
FDisbleCaption := 'Disabled';
FEnableCaption := 'Enabled';
FCheckBox.Caption := FDisbleCaption;
FEdit := TEdit.Create(Self);
FEdit.Parent := Self;
FEdit.Align := alTop;
FEdit.Enabled := False;
Self.Height := 40;
Self.Width := 185;
Self.AutoSize := True;
end;
destructor TCheckEdit.Destroy;
begin
FEdit.Free;
FCheckBox.Free;
inherited;
end;
function TCheckEdit.GetIsActive: Boolean;
begin
if FCheckBox.Checked then
Result := True
else
Result := False;
end;
procedure TCheckEdit.SetDisbleCaption(const Value: TCaption);
begin
FDisbleCaption := Value;
end;
procedure TCheckEdit.SetEnableCaption(const Value: TCaption);
begin
FEnableCaption := Value;
end;
procedure TCheckEdit.SetIsActive(const Value: Boolean);
begin
FCheckBox.Checked := Value;
case Value of
True :
begin
FEdit.Enabled := True;
FCheckBox.Caption := FEnableCaption;
end;
False :
begin
FEdit.Enabled := False;
FCheckBox.Caption := FDisbleCaption;
end;
end;
end;
end.
一切正常,但我想在一个节点中制作 EnableCaption
和 DisableCaption
,因为 TToggleSwitch
有 StateCaptions
属性,当我更改标题也会在 CheckBox
中更改它。
我尝试在 SetEnableCaption
和 SetDisbleCaption
过程中调用 Invalidate;
,但这不起作用。
我该怎么做?
老实说,一开始我不想回答这个问题,因为你已经在 SO
上的一个问题中找到了答案第一个class准确的说是TPersistent
暴露了TNCRSpeedButton
中的Glyph坐标。
我写这篇文章是因为我说过 我希望你能从中受益。 我可以看出你没有。
这就是您的问题解决方案,非常欢迎您询问有关它是如何实施的任何问题。
unit UnitName;;
interface
uses
System.Classes, Vcl.ExtCtrls, Vcl.StdCtrls, Vcl.Controls;
type
TCheckEditCaptions = class(TPersistent)
private
FDisableCaption: TCaption;
FEnableCaption: TCaption;
FOnChange: TNotifyEvent;
function GetDisableCaption: TCaption;
function GetEnableCaption: TCaption;
procedure SetDisableCaption(const Value: TCaption);
procedure SetEnableCaption(const Value: TCaption);
public
procedure Assign(aValue: TPersistent); override;
published
property EnableCaption: TCaption read GetEnableCaption write SetEnableCaption;
property DisableCaption: TCaption read GetDisableCaption write SetDisableCaption;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
TCheckEdit = class (TCustomControl)
private
FCheckBox : TCheckBox;
FEdit : TEdit;
FCheckEditCaptions: TCheckEditCaptions;
procedure SetIsActive(const Value: Boolean);
function GetIsActive : Boolean;
procedure ChBoxOnClick (Sender : TObject);
procedure CheckEditCaptionsChanged(Sender : TObject);
procedure SetCheckEditCaptions(const Value: TCheckEditCaptions);
protected
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
property IsActive : Boolean read GetIsActive write SetIsActive default False;
property CheckEditCaptions : TCheckEditCaptions read FCheckEditCaptions write SetCheckEditCaptions;
property OnClick;
end;
procedure register;
implementation
procedure register;
begin
RegisterComponents('Samples', [TCheckEdit]);
end;
{ TCheckEdit }
procedure TCheckEdit.ChBoxOnClick(Sender: TObject);
begin
IsActive := FCheckBox.Checked;
end;
procedure TCheckEdit.CheckEditCaptionsChanged(Sender: TObject);
begin
SetIsActive(GetIsActive);
end;
constructor TCheckEdit.Create(AOwner: TComponent);
begin
inherited;
FCheckBox := TCheckBox.Create(Self);
FCheckBox.Parent := Self;
FCheckBox.Align := alTop;
FCheckBox.OnClick := ChBoxOnClick;
FCheckEditCaptions := TCheckEditCaptions.Create;
FCheckEditCaptions.FDisableCaption := 'Disabled';
FCheckEditCaptions.FEnableCaption := 'Enabled';
FCheckEditCaptions.OnChange := CheckEditCaptionsChanged;
FCheckBox.Caption := CheckEditCaptions.DisableCaption;
FEdit := TEdit.Create(Self);
FEdit.Parent := Self;
FEdit.Align := alTop;
FEdit.Enabled := False;
Self.Height := 40;
Self.Width := 185;
Self.AutoSize := True;
end;
destructor TCheckEdit.Destroy;
begin
FEdit.Free;
FCheckBox.Free;
FCheckEditCaptions.Free;
inherited;
end;
function TCheckEdit.GetIsActive: Boolean;
begin
Result := FCheckBox.Checked ;
end;
procedure TCheckEdit.SetCheckEditCaptions(const Value: TCheckEditCaptions);
begin
FCheckEditCaptions.Assign(Value);
end;
procedure TCheckEdit.SetIsActive(const Value: Boolean);
begin
FCheckBox.Checked := Value;
FEdit.Enabled := Value;
if Value then
FCheckBox.Caption := CheckEditCaptions.EnableCaption
else
FCheckBox.Caption := CheckEditCaptions.DisableCaption;
end;
{ TCheckEditCaptions }
procedure TCheckEditCaptions.Assign(aValue: TPersistent);
begin
if aValue is TCheckEditCaptions then begin
FEnableCaption := TCheckEditCaptions(aValue).FEnableCaption;
FEnableCaption := TCheckEditCaptions(aValue).FDisableCaption;
if Assigned(FOnChange) then
FOnChange(self);
end else
inherited;
end;
function TCheckEditCaptions.GetDisableCaption: TCaption;
begin
result := FDisableCaption;
end;
function TCheckEditCaptions.GetEnableCaption: TCaption;
begin
result := FEnableCaption;
end;
procedure TCheckEditCaptions.SetDisableCaption(const Value: TCaption);
begin
FDisableCaption := Value;
if Assigned(FOnChange) then
FOnChange(self);
end;
procedure TCheckEditCaptions.SetEnableCaption(const Value: TCaption);
begin
FEnableCaption := Value;
if Assigned(FOnChange) then
FOnChange(self);
end;
end.