I have a check box control with a labeled edit as a published subcomponent.
What I'm trying to do is create a Translate procedure for the check box that would show the labeled edit on top, and allow the user to change the text of the check box's caption. Something like this:
constructor TPBxCheckBox.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FTranslateEdit := TLabeledEdit.Create(Self);
FTranslateEdit.Parent := Self.Parent;
FTranslateEdit.SetSubComponent(True);
FTranslateEdit.Visible := False;
end;
procedure TPBxCheckBox.Translate(Show: Boolean);
begin
TranslateEdit.Left := Self.Left;
TranslateEdit.Top := Self.Top;
TranslateEdit.EditLabel.Caption := Self.Caption;
TranslateEdit.Text := Self.Caption;
TranslateEdit.Visible := Show;
TranslateEdit.Width := Self.Width;
end;
But this doesn't work - the labeled edit is never shown.
What am I doing wrong here?
It doesn't show because at TPBxCheckBox.Create()
time Parent
isn't yet assigned, so you're basically doing TranslateEdit.Parent := nil;
.
If you really want your TranslatedEdit to have the same parent as the TPBxCheckBox itself, you could override SetParet
and take action at the moment TPBxCheckBox's Parent is Assigned. Something like this:
TPBxCheckBox = class(TWhatever)
protected
procedure SetParent(AParent: TWinControl); override;
end;
procedure TPBxCheckBox.SetParent(AParent: TWinControl);
begin
inherited;
TranslatedEdit.Parent := AParent;
end;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With