I'm trying to create a new component named CheckEdit
as the following:
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.
Everything is working fine, but I want to make EnableCaption
and DisableCaption
in one node as TToggleSwitch
have StateCaptions
property, and when I change the caption it will change it in the CheckBox
too.
I try to call Invalidate;
in SetEnableCaption
and SetDisbleCaption
procedures, but that does not work.
How can I do that?