Creating TMyPageControl component

What I want to do is creating a Custom component descendant from TPageControl like:
TMyPageControl = class(TPageControl)

but what I realy need is inserting new property items on TTabSheet control like:

TMyTabSheet = class(TTabSheet)
property Item1;
property Item2;
property Item3;

and this TMyTabSheet to be linked with TMyPageControl.
So how can I link this to controls and to function on the same way as TPageControl?

Thank you
isakaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

edeyCommented:
you just declare your new tabsheet (TMyTabSheet), create an instance of it & set it's pageControl property to your pageControl.

Gl
Mike
0
edeyCommented:
here I have an example clipped from a text editor I have written:

  TMySheet = class(TTabSheet)
  private
     fFileName : string;
     procedure setFileName(value : string);
  public
     text : TRichEdit;
     property fileName : string read fFileName write setFileName;
     constructor create(AOwner : TComponent);override;
  end;

constructor TMySheet.create(AOwner : TComponent);
begin
     inherited;
     text := TRichEdit.create(self);
     text.parent := self;
     text.align := alClient;
     text.modified := false;
     text.ScrollBars := ssBoth;
     text.PlainText := form1.CheckBox1.Checked;
     form1.toolbutton3.down := form1.checkbox1.checked;
     text.WordWrap := form1.checkbox5.checked;
     form1.toolButton2.Down := form1.checkbox5.checked;
     text.WantTabs := true;
     text.WantReturns := true;
     fFileName := '';
end;

procedure TForm1.New1Click(Sender: TObject);
var
   t : TMySheet;
begin
     t := TMySheet.create(noteBook);
     with t do
     begin
          parent := notebook;
          pageControl := noteBook;
     end;
     notebook.ActivePage := t;
     noteBookChange(self);
end;



GL
Mike
0
isakaAuthor Commented:
Thank you Mike on you answer,

But in this way I can't make a component which work at design time.

isak
0
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

isakaAuthor Commented:
Adjusted points from 50 to 100
0
mullet_attackCommented:
isaka,
A subclassed PageControl has been something I've wanted often also, so your question made me act. It seems to work, although not fully tested yet. I would appreciate your feedback.

for the example I added a property called 'framed' to MyTabSheet. I couldn't think of anything useful to do :-)

The overridden property editors allow design time adding of MyTabSheets.

-------------------------------------
unit MyPage;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, DsgnIntf, menus, editintf;

type
  TMyPageControl = class;  // forward declaration
  TMyPageEditor = class(TComponentEditor)
  function GetVerbCount:integer;override;
  function GetVerb(index:integer):string;override;
  procedure ExecuteVerb(index:integer);override;
 end;

  TMyTabEditor = class(TComponentEditor)
  function GetVerbCount:integer;override;
  function GetVerb(index:integer):string;override;
  procedure ExecuteVerb(index:integer);override;
 end;

  TMyTabSheet = class(TTabSheet)
  private
    FFramed: boolean;
    function GetMyPageControl: TMyPageControl;
    procedure SetMyPageControl(const Value: TMyPageControl);
    procedure SetFramed(const Value: boolean);
  protected
    property PageControl: TMyPageControl read GetMyPageControl write SetMyPageControl;
  public
    constructor Create(AOwner : TComponent);override;
  published
    property Framed : boolean read FFramed write SetFramed default false;
  end;

  TMyPageControl = class(TPageControl)
  private
    function GetPage(Index: Integer): TMyTabSheet;
    procedure SetActivePage(const Value: TMyTabSheet);
    function GetActivePage :  TMyTabSheet;
  protected
    { Protected declarations }
  public
    property Pages[Index: Integer]: TMyTabSheet read GetPage;
  published
    property ActivePage: TMyTabSheet read GetActivePage write SetActivePage;
end;

procedure Register;
function FindUniqueName(Component : TComponent ; const NewName: string): string;

implementation

procedure Register;
begin
  RegisterNoIcon([TMyTabSheet]);
  RegisterClass(TMyTabSheet);
  RegisterComponents('Planetech', [TMyPageControl]);
  RegisterComponentEditor(TMyPageControl,TMyPageEditor);
  RegisterComponentEditor(TMyTabSheet,TMyTabEditor);
end;

{ TMyPageControl }

function TMyPageControl.GetActivePage: TMyTabSheet;
begin
  result := TMyTabSheet(inherited ActivePage);
end;

function TMyPageControl.GetPage(Index: Integer): TMyTabSheet;
begin
  result := TMyTabSheet(inherited Pages[Index]);
end;

procedure TMyPageControl.SetActivePage(const Value: TMyTabSheet);
begin
  inherited ActivePage := (TMyTabSheet(Value));
end;

{ TMyTabSheet }

constructor TMyTabSheet.Create(AOwner: TComponent);
begin
  inherited;
  fframed := false;
end;

function TMyTabSheet.GetMyPageControl: TMyPageControl;
begin
  result := TMyPageControl(inherited PageControl);
end;

procedure TMyTabSheet.SetFramed(const Value: boolean);
begin
  FFramed := Value;
  if fFramed then
    ControlStyle := ControlStyle + [csFramed]
  else
    ControlStyle := ControlStyle - [csFramed];
  RecreateWnd;
end;

procedure TMyTabSheet.SetMyPageControl(const Value: TMyPageControl);
begin
  inherited PageControl := TPageControl(value);
end;

{ TMyPageEditor }

procedure TMyPageEditor.ExecuteVerb(index: integer);
var
 tempMyTabSheet : TMyTabSheet;
begin
  inherited;
  case index of
    0:
      begin
        tempMyTabSheet := TMyTabSheet.create(TMyPageControl(Component).Owner);
        tempMyTabSheet.PageControl := TMyPageControl(Component);
        tempMyTabSheet.name := FindUniqueName(component,'MyTabSheet');
        designer.modified;
      end;
    1: with component as TMyPageControl do
        if ActivePageIndex = PageCount -1 then
          ActivePage := Pages[0]
        else
          ActivePage := Pages[ActivePageIndex + 1];
    2: with component as TMyPageControl do
        if ActivePageIndex = 0 then
          ActivePage := Pages[PageCount -1]
        else
          ActivePage := Pages[ActivePageIndex - 1];
    3:
      begin
        TMyTabSheet(TMyPageControl(Component).ActivePage).free;
        designer.modified;
      end;
  end;
end;

function TMyPageEditor.GetVerb(index: integer): string;
begin
 case index of
  0:Result := 'New Page';
  1:Result := 'Next Page';
  2:Result := 'Previous Page';
  3:Result := 'Delete Page';
 end;
end;

function TMyPageEditor.GetVerbCount: integer;
begin
  result := 4;
end;

{ TMyTabEditor }

procedure TMyTabEditor.ExecuteVerb(index: integer);
var
 tempMyTabSheet : TMyTabSheet;
begin
  inherited;
  case index of
    0:
      begin
        tempMyTabSheet := TMyTabSheet.create(TMyTabSheet(Component).Owner);
        tempMyTabSheet.PageControl := TMyPageControl(TMyTabSheet(Component).PageControl);
        tempMyTabSheet.name := FindUniqueName(component, 'MyTabSheet');
        designer.modified;
      end;
    1: with TMyTabSheet(component).PageControl as TMyPageControl do
        if ActivePageIndex = PageCount -1 then
          ActivePage := Pages[0]
        else
          ActivePage := Pages[ActivePageIndex + 1];
    2: with TMyTabSheet(component).PageControl as TMyPageControl do
        if ActivePageIndex = 0 then
          ActivePage := Pages[PageCount -1]
        else
          ActivePage := Pages[ActivePageIndex - 1];
    3:
      begin
        TMyTabSheet(component).free;
        designer.modified;
      end;
  end;
end;

function TMyTabEditor.GetVerb(index: integer): string;
begin
 case index of
  0:Result := 'New Page';
  1:Result := 'Next Page';
  2:Result := 'Previous Page';
  3:Result := 'Delete Page';
 end;
end;

function TMyTabEditor.GetVerbCount: integer;
begin
  result := 4;
end;

function FindUniqueName(Component : TComponent ; const NewName: string): string;
var
    t : Integer;
    n : integer;
begin
  n := 0;
  Result := Format('%s%d', [NewName, n]);
  with (Component.owner) as TForm do
    begin
      While FindComponent(result) <> nil do
        begin
          inc(n);
          Result := Format('%s%d', [NewName, n]);
        end;
    end;
end;

end.

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
isakaAuthor Commented:
It works perfect.
Thank you for your brilliant answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.