Solved

Creating TMyPageControl component

Posted on 2000-05-09
6
223 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:isaka
  • 3
  • 2
6 Comments
 
LVL 6

Expert Comment

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

Gl
Mike
0
 
LVL 6

Expert Comment

by:edey
ID: 2793313
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
 

Author Comment

by:isaka
ID: 2793560
Thank you Mike on you answer,

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

isak
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:isaka
ID: 2793835
Adjusted points from 50 to 100
0
 
LVL 2

Accepted Solution

by:
mullet_attack earned 100 total points
ID: 2794040
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
 

Author Comment

by:isaka
ID: 2804281
It works perfect.
Thank you for your brilliant answer.
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now