Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent Delphi IDE creating component icons at design time

I have created a custom control TOuterControl that is the parent for multiple TInnerControls.

Everything is working fine except that the IDE is creating icons for each the child TInnerControl's (InnerControl1 and InnerControl2 in the screenshot). How do I prevent the IDE from generating the icons?

alt text

unit TestControl;

interface

Procedure Register;

implementation

Uses
    Classes,
    Controls,
    SysUtils,
    DesignEditors,
    DesignIntf,
    VCLEditors;

Type

TOuterControl = Class;

TInnerControl = Class(TComponent)
Protected
    FOuterControl : TOuterControl;

    function GetParentComponent: TComponent; Override;
    Function HasParent : Boolean; Override;
    procedure SetParentComponent                  (Value: TComponent); Override;
End;

TOuterControl = Class(TCustomControl)
Protected
    FInnerControls : TList;

    Procedure Paint; Override;
Public
    Constructor Create(AOwner : TComponent); Override;
    Procedure AddInnerControl(AInnerControl : TInnerControl);
    procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
End;

TOuterControlEditor = Class(TDefaultEditor)
Public
    Procedure ExecuteVerb(Index : Integer);          Override;
    Function  GetVerb    (Index : Integer) : String; Override;
    Function  GetVerbCount      : Integer;           Override;
End;

procedure TOuterControl.AddInnerControl(AInnerControl: TInnerControl);
begin
    AInnerControl.FOuterControl := Self;;
    FInnerControls.Add(AInnerControl);
    Invalidate;
end;

constructor TOuterControl.Create(AOwner: TComponent);
begin
    inherited;

    FInnerControls := TList.Create;
end;

procedure TOuterControl.GetChildren(Proc: TGetChildProc; Root: TComponent);
var
    I : Integer;
begin
    inherited;

    For I := 0 To FInnerControls.Count - 1 Do
        Proc(FInnerControls[I]);
end;

procedure TOuterControl.Paint;
begin
    inherited;

    Canvas.FillRect(ClientRect);
    Canvas.TextOut(0,0, Format('Inner Control Count = %d', [FInnerControls.Count]));
end;

function TInnerControl.GetParentComponent: TComponent;
begin
    Result := FOuterControl;
end;

function TInnerControl.HasParent: Boolean;
begin
    Result := True;
end;

procedure TInnerControl.SetParentComponent(Value: TComponent);
begin
    If Value Is TOuterControl Then
        If FOuterControl <> Value Then
    Begin
        FOuterControl := TOuterControl(Value);
        FOuterControl.AddInnerControl(Self);
    End;
end;

procedure TOuterControlEditor.ExecuteVerb(Index: Integer);
Var
    OuterControl : TOuterControl;
    InnerControl : TInnerControl;
begin
    inherited;

    OuterControl := TOuterControl(Component);

    If Index = 0 Then
    Begin
        InnerControl := TInnerControl.Create(OuterControl.Owner);
        OuterControl.AddInnerControl(InnerControl);
    End;
end;

function TOuterControlEditor.GetVerb(Index: Integer): String;
begin
    Result := 'Add Inner';
end;

function TOuterControlEditor.GetVerbCount: Integer;
begin
    Result := 1;
end;

Procedure Register;
Begin
    RegisterComponents('AA', [TOuterControl]);
    RegisterComponentEditor(TOuterControl, TOuterControlEditor);
End;


Initialization
    Classes.RegisterClasses([TInnerControl]);

end.
like image 986
Frank Avatar asked Nov 22 '10 04:11

Frank


3 Answers

You can prevent them from appeaing on the form with:

RegisterNoIcon([TInnerControl]);

More info on RegisterNoIcon can be found at http://docwiki.embarcadero.com/VCL/e/index.php/Classes.RegisterNoIcon

It's a little confusing having classes with a name that end with "Control" that aren't normal visual controls though.

like image 134
Dan Bartlett Avatar answered Nov 15 '22 07:11

Dan Bartlett


If TInnerControl is meant to be used only inside a TOuterControl, then you should call SetSubComponent(True) during/after the TInnerControl's creation.

like image 21
Remy Lebeau Avatar answered Nov 15 '22 06:11

Remy Lebeau


When you create the inner controls, you tell them that their owner is the form (the owner of the outer control). Therefore, the form draws them, just like it draws all the other components it owns. You probably want the outer control to own the inner ones.

like image 42
Rob Kennedy Avatar answered Nov 15 '22 08:11

Rob Kennedy