Reputation: 1116
I have created a PageControl like component derived from Tcustomcontrol which hosts child tabsheets derived from TcustomPanel.
The Tabsheets are created by the host pagecontrol via a newpage method or by creating a new tabsheet and setting its PageControl property, pretty much the same as the standard pagecontrol.
I created the property editor for the Pagecontrol with the "Add Page" verb.
Since the Tabsheet is not on the component pallete, I created the RegisterClass entry in the designer code.
This all works OK and I could created the child tabsheets and even select them in the designer and set the properties.
Trouble is, the new pages have no name and show up as "Unnamed" in the object inspector and do not show up on the Form structure tree diagram.
After some searching I found an example on Stackoverflow that showed that a
RegisterNoIcon([Myclass]) needed to be added along with the registerClass.
I did this and the component now shows up on the form tree but as generic "Component[14]" and the child still shows as "unnamed" in the object inspector.
Obviously the Integrated Pagecontrol/tabsheet has some extra sauce that registers the component properly with the designer, but i'm struggling to find what it is.
The property registration currently looks like
procedure Register;
begin
RegisterComponents('My Page Control', [TMyPageControl,TMytitlebar,TMyTabset]);
RegisterComponentEditor (TMypageControl, TMyCompEditor);
RegisterComponentEditor (TMyTabSet, TMyTabEditor);
RegisterClass(TMytabSheet);
RegisterNoIcon([TMytabSheet]);
end;
and the edit code is
procedure TMyCompEditor.ExecuteVerb(Index: Integer);
var ts:MyTabsheet;
begin
inherited;
case Index of
0: with Component as TMyPageControl do
begin
Ts:=TmyTabsheet.Create(Owner);
Ts.Pagecontrol:=(Component as TMyPageControl);
end;
end;
end;
As a test in the property editor I tried added a standard button to the custom control with the same result.
Any Ideas?
Upvotes: 2
Views: 203
Reputation: 47704
Seems you have to set the name yourself. Add a line
Ts.Name := Designer.UniqueName(Ts.ClassName);
after the TMyTabSheet creation.
Side note 1: Don't use someones Owner! Instead use Designer.Root
.
Side note 2: Don't use with!
(it is even unnecessary as TComponent
already introduces the Owner property)
So your code should better look like this:
case Index of
0: begin
Ts := TmyTabsheet.Create(Designer.Root);
Ts.Name := Designer.UniqueName(Ts.ClassName);
Ts.Pagecontrol := (Component as TMyPageControl);
end;
end;
Upvotes: 6