3

I have my own control, derived from TCustomPanel. It has a child (TEdit) on it.

type
  TMyControl = class(TCustomPanel)
  private
    FEditor: TEdit;
  public
    constructor Create(AOwner: TComponent);
    destructor Destroy(); override;
  end;

  constructor TMyControl.Create(AOwner: TComponent);
  begin
    FEditor := TEdit.Create(nil);
    FEditor.Parent := Self;
  end;

  destructor TMyControl.Destroy(); 
  begin
    FEditor.Free();
  end;

When I click on a child control at design-time, it acts as the run-time TEdit, capturing focus.

How to completely disable child controls at design time?

I want them to stop answering mouse/keyboard messages. When I click on them at design-time, I want the parent control to be selected and dragged.

Andrew
  • 3,696
  • 3
  • 40
  • 71
  • Can it be dragged inside it's parent? If not, it isn't the designer that's giving you trouble. Try to disable the edit in designtime. – GolezTrol Jun 26 '12 at 14:37
  • @GolezTrol Yes, when child control disabled, everythign works fine. However, the look is different (grayed). – Andrew Jun 26 '12 at 14:45

1 Answers1

6

Use Self as the owner in the edit constructor to make your edit sub-component of your panel and to let the panel handle its destruction. And call SetSubComponent function with the IsSubComponent paremeter set to True for each sub-component to see your panel control as one in the structure pane.

constructor TMyControl.Create(AOwner: TComponent);
begin
  ...
  FEditor := TEdit.Create(Self);
  FEditor.SetSubComponent(True);
  FEditor.Parent := Self;
  ...
end;
TLama
  • 75,147
  • 17
  • 214
  • 392
  • Yes, thank you! However, it works even without `SetSubComponent(True);`, maybe it is not necessary? – Andrew Jun 26 '12 at 14:57
  • Yes it will, but the [`SetSubComponent`](http://docwiki.embarcadero.com/Libraries/en/System.Classes.TComponent.SetSubComponent) causes that you'll see your panel always as one control in the `Structure` pane. It was discussed [`here`](http://stackoverflow.com/q/9479872/960757). – TLama Jun 26 '12 at 15:02