Board index » delphi » Modifying a TPageControl - D7

Modifying a TPageControl - D7


2003-09-27 10:07:42 PM
delphi198
I have been trying to modify a TPageControl in Delphi 7 to use TTabSheets
with an added colour property. I have created a modified TTabSheet with this
property which works fine as a standalone but I am struggling to find the
best way to make this used by TPageControl as its TabSheet. Could anyone be
so kind as to suggest the best way to do this please ? eg. Do I have to
attempt to override all the procedures of TPageControl that call TTabSheet
to use my new TTabSheet or is there an easier way to accomplish this. I'm
pretty new to this aspect of Delphi - if it doesn't show already - but I
really would appreciate some guidance in achieving this.
my thanks in anticipation
Peter B.
PS. If you're wondering why I want to do this, it is simply to exercise
control over the way Win XP presents the Page Control at runtime. The Win XP
theming wrecks the way the program looks which was not an issue under my
previous Delphi 4 / Win 9x compilations.
 
 

Re:Modifying a TPageControl - D7

In article <3f759a10$XXXX@XXXXX.COM>, Peter B. writes:
Quote
I have been trying to modify a TPageControl in Delphi 7 to use TTabSheets
with an added colour property. I have created a modified TTabSheet with this
property which works fine as a standalone but I am struggling to find the
best way to make this used by TPageControl as its TabSheet.
If you study the source code of TPagecontrol you will find no place where it
ever creates a tabsheet on its own. Instead it has an InsertPage method that
is called by the TTabSheet.SetPagecontrol method to link the tabsheet to the
pagecontrol. So, what does create a new tabsheet in the designer? A component
editor associated with TPagecontrol. You need to replace that with a component
editor of your own.
If you need help on doing that ask in b.p.d.vcl.components.writing.
Peter Below (TeamB)
Use the newsgroup archives :
www.mers.com/searchsite.html
www.tamaracka.com/search.htm
groups.google.com
www.prolix.be
 

Re:Modifying a TPageControl - D7

Hi
I recently wrote the following in the vcl.components.using newsgroup :-
Quote
I have been trying to modify a TPageControl in Delphi 7 to use TTabSheets
with an added colour property. I have created a modified TTabSheet with
this
property which works fine as a standalone but I am struggling to find the
best way to make this used by TPageControl as its TabSheet. Could anyone be
so kind as to suggest the best way to do this please ? eg. Do I have to
attempt to override all the procedures of TPageControl that call TTabSheet
to use my new TTabSheet or is there an easier way to accomplish this. I'm
pretty new to this aspect of Delphi - if it doesn't show already - but I
really would appreciate some guidance in achieving this.
my thanks in anticipation
Peter B.
PS. If you're wondering why I want to do this, it is simply to exercise
control over the way Win XP presents the Page Control at runtime. The Win
XP
theming wrecks the way the program looks which was not an issue under my
previous Delphi 4 / Win 9x compilations.
Peter Below (Team B) replied with the following and suggested I move to this
newsgroup for possible further help :-
Quote
If you study the source code of TPagecontrol you will find no place where
it
ever creates a tabsheet on its own. Instead it has an InsertPage method
that
is called by the TTabSheet.SetPagecontrol method to link the tabsheet to
the
pagecontrol. So, what does create a new tabsheet in the designer? A
component
editor associated with TPagecontrol. You need to replace that with a
component
editor of your own.
I have written the new component editor for TPageControl as suggested and it
operates fine when tested eg. with returning a simple MessageDlg() but I'm
still very stuck on the actual coding for the Index items in my component
editor. I am still working on the basis that I have to override the
InsertPage and RemovePage procedures (amongst others) of TPageControl
(ComCtrls.pas) and then rewrite these procedures to call my modified
TTabSheet and subsequently call them from the ExecuteVerb procedure of my
new Component Editor. Does this seem correct ? or am I going about this in
the wrong way ?
Mostly whatever I try, I end up with the compiler telling me that the method
I'm trying to override is not in the base class - which as far as I can see
it is. Or, if I make it past the compiler I just get run time errors which I
have been unable to sort out. Could anyone be so kind as to assist with this
issue because I am now thoroughly lost !
thanks again in anticipation
Peter B.
 

Re:Modifying a TPageControl - D7

Hi Peter!
"Peter B." <XXXX@XXXXX.COM>píše v diskusním příspěvku
Quote
I'm still working on the basis that I have to override the
InsertPage and RemovePage procedures (amongst others) of TPageControl
(ComCtrls.pas)
Mostly whatever I try, I end up with the compiler telling me that the
method
I'm trying to override is not in the base class - which as far as I can
see
it is.
From what I can see in my Delphi 7 source, TPageControl's InsertPage & RemovePage
methods neither are visible to anyone outside ComCtrls unit since they're
declared as private, nor they can be overriden since they are declared as
static methods.
Best regards,
Ivo
 

Re:Modifying a TPageControl - D7

Thanks Ivo, I am really not being very clever here ! I guess that is what I
get for trying to hurry instead of taking a long hard sensible look at what
I'm trying to do. I am still not understanding how to deal with this issue
though. How can I achieve this aim if I cannot exert any influence over the
InsertPage / RemovePage methods or am I looking at writing a PageControl
from scratch ?
thanks
Peter B.
"Ivo Bauer" <XXXX@XXXXX.COM>writes
Quote
Hi Peter!

"Peter B." <XXXX@XXXXX.COM>píse v diskusním příspěvku
news:XXXX@XXXXX.COM...
>I'm still working on the basis that I have to override the
>InsertPage and RemovePage procedures (amongst others) of TPageControl
>(ComCtrls.pas)
>Mostly whatever I try, I end up with the compiler telling me that the
method
>I'm trying to override is not in the base class - which as far as I can
see
>it is.


From what I can see in my Delphi 7 source, TPageControl's InsertPage &
RemovePage
methods neither are visible to anyone outside ComCtrls unit since they're
declared as private, nor they can be overriden since they are declared as
static methods.


Best regards,
Ivo


 

Re:Modifying a TPageControl - D7

"Peter B." <XXXX@XXXXX.COM>writes
Quote
Thanks Ivo, I am really not being very clever here ! I guess that is what I
get for trying to hurry instead of taking a long hard sensible look at
what
I'm trying to do. I am still not understanding how to deal with this issue
though. How can I achieve this aim if I cannot exert any influence over
the
InsertPage / RemovePage methods or am I looking at writing a PageControl
from scratch ?
Peter Below's hint was to use the TTabSheet.SetPagecontrol method.
// This removes a tabsheet from a page control...
MyTabSheetClass.SetPageControl(nil);
// this adds a tabsheet to a page control
MyTabSheetClass.SetPageControl(somePageControl);
If the your tabsheet derives from a TTabSheet then the object inspector
should have no problem modifying the pageindexes. Likewise, in your
TPageControl descendent's new editor, to add a new tab sheet in response the
'New Page' menu, simply create your descendent tabsheet and call
YourNewTabSheet.SetPageControl(the page control used by the editor).
All other functionality should work as normal for a TPageControl. You only
have to implement your painting for your tabsheet class.
Regards
Ian Stuart
 

Re:Modifying a TPageControl - D7

"Ian Stuart" <XXXX@XXXXX.COM>writes
Quote
"Peter B." <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>Thanks Ivo, I am really not being very clever here ! I guess that is what
I
>get for trying to hurry instead of taking a long hard sensible look at
what
>I'm trying to do. I am still not understanding how to deal with this
issue
>though. How can I achieve this aim if I cannot exert any influence over
the
>InsertPage / RemovePage methods or am I looking at writing a PageControl
>from scratch ?


Peter Below's hint was to use the TTabSheet.SetPagecontrol method.

// This removes a tabsheet from a page control...
MyTabSheetClass.SetPageControl(nil);

// this adds a tabsheet to a page control
MyTabSheetClass.SetPageControl(somePageControl);


If the your tabsheet derives from a TTabSheet then the object inspector
should have no problem modifying the pageindexes. Likewise, in your
TPageControl descendent's new editor, to add a new tab sheet in response
the
'New Page' menu, simply create your descendent tabsheet and call
YourNewTabSheet.SetPageControl(the page control used by the editor).

All other functionality should work as normal for a TPageControl. You only
have to implement your painting for your tabsheet class.


Regards
Ian Stuart


Oops, what I meant was....
TTabSheet.PageControl property SETS or GETS the TPageControl - (using
SetPageControl)
MyTabSheet.PageControl := SomePageControl;
MyTabSheet.PageControl := nil;
 

Re:Modifying a TPageControl - D7

Hi Ian!
"Ian Stuart" <XXXX@XXXXX.COM>píše v diskusním příspěvku
Quote
TTabSheet.PageControl property SETS or GETS the TPageControl - (using
SetPageControl)

MyTabSheet.PageControl := SomePageControl;
MyTabSheet.PageControl := nil;
Yes, that is probably the best way how to do it. I just wonder if there is a
source code for standard TPageControl component editor available. I did the
search but found none.
Best regards,
Ivo
 

Re:Modifying a TPageControl - D7

Ian & Ivo
Firstly an apology for letting this thread lapse for several days due to
the needs of other projects. Secondly, my thanks to you both for your
contributions. This is my first ever effort in this area and I am learning
much and making even more mistakes. I have included the code for the
modified component / component editor I have written which doesn't work. I've
tried various ideas but at best achieved the odd access violation. Could you
be so kind as to let me know where and why this is incorrect ? - I think my
understanding has a fair way to go yet !
unit PBXPageControl;
interface
uses
SysUtils, Classes, Controls, ComCtrls, Graphics, DesignIntF,
DesignEditors;
type
TPBXPageControl = class(TPageControl)
published
constructor Create(AOwner: TComponent); override;
end;
type
TColorTabSheet = class(TTabSheet) {DECLARE NEW COLOURED TABSHEET
CLASS}
published
property Color default clBtnFace;
end;
procedure Register;
implementation
constructor TPBXPageControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
{------------------------------ COMPONENT
EDITOR ------------------------------}
type
TPBXPageControlEditor = class(TComponentEditor)
private
procedure ExecuteVerb(Index: integer); override;
function GetVerbCount: integer; override;
function GetVerb(Index: integer): string; override;
end;
procedure TPBXPageControlEditor.ExecuteVerb(Index: integer);
var
APageCtrl: TPBXPageControl;
APage: TColorTabSheet;
begin
case Index of
0: begin
APage.PageControl := APageCtrl;
APageCtrl.Repaint;
Designer.Modified;
end;
1: begin
APage.PageControl := nil;
APageCtrl.Repaint;
Designer.Modified;
end;
end;
end;
function TPBXPageControlEditor.GetVerbCount: integer;
begin
Result := 2;
end;
function TPBXPageControlEditor.GetVerb(Index: integer): string;
begin
case Index of
0: Result := 'Insert New Coloured Page';
1: Result := 'Delete Coloured Page';
end;
end;
{---------------------------------------------------------------------------
---}
procedure Register;
begin
RegisterClass(TColorTabSheet);
RegisterComponents('Custom', [TPBXPageControl]);
RegisterComponentEditor(TPBXPageControl, TPBXPageControlEditor);
end;
end.
"Ivo Bauer" <XXXX@XXXXX.COM>writes
Quote
Hi Ian!

"Ian Stuart" <XXXX@XXXXX.COM>píše v diskusním příspěvku
news:XXXX@XXXXX.COM...

>TTabSheet.PageControl property SETS or GETS the TPageControl - (using
>SetPageControl)
>
>MyTabSheet.PageControl := SomePageControl;
>MyTabSheet.PageControl := nil;


Yes, that is probably the best way how to do it. I just wonder if there is
a
source code for standard TPageControl component editor available. I did
the
search but found none.


Best regards,
Ivo


 

Re:Modifying a TPageControl - D7

Decided to start a new thread with this. The previous one (28/09/2003) will
probably be a bit cold by now.
Ian & Ivo
Firstly an apology for letting this thread lapse for several days due to
the needs of other projects. Secondly, my thanks to you both for your
contributions. This is my first ever effort in this area and I am learning
much and making even more mistakes. I have included the code for the
modified component / component editor I have written (which doesn't work).
I've
tried various ideas but at best achieved the odd access violation. Could you
be so kind as to let me know where and why this is incorrect ? - I think my
understanding has a fair way to go yet !
unit PBXPageControl;
interface
uses
SysUtils, Classes, Controls, ComCtrls, Graphics, DesignIntF,
DesignEditors;
type
TPBXPageControl = class(TPageControl)
published
constructor Create(AOwner: TComponent); override;
end;
type
TColorTabSheet = class(TTabSheet) {DECLARE NEW COLOURED TABSHEET
CLASS}
published
property Color default clBtnFace;
end;
procedure Register;
implementation
constructor TPBXPageControl.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
end;
{------------------------------ COMPONENT
EDITOR ------------------------------}
type
TPBXPageControlEditor = class(TComponentEditor)
private
procedure ExecuteVerb(Index: integer); override;
function GetVerbCount: integer; override;
function GetVerb(Index: integer): string; override;
end;
procedure TPBXPageControlEditor.ExecuteVerb(Index: integer);
var
APageCtrl: TPBXPageControl;
APage: TColorTabSheet;
begin
case Index of
0: begin
APage.PageControl := APageCtrl;
APageCtrl.Repaint;
Designer.Modified;
end;
1: begin
APage.PageControl := nil;
APageCtrl.Repaint;
Designer.Modified;
end;
end;
end;
function TPBXPageControlEditor.GetVerbCount: integer;
begin
Result := 2;
end;
function TPBXPageControlEditor.GetVerb(Index: integer): string;
begin
case Index of
0: Result := 'Insert New Coloured Page';
1: Result := 'Delete Coloured Page';
end;
end;
{---------------------------------------------------------------------------
---}
procedure Register;
begin
RegisterClass(TColorTabSheet);
RegisterComponents('Custom', [TPBXPageControl]);
RegisterComponentEditor(TPBXPageControl, TPBXPageControlEditor);
end;
end.
"Ivo Bauer" <XXXX@XXXXX.COM>writes
Quote
Hi Ian!

"Ian Stuart" <XXXX@XXXXX.COM>píše v diskusním příspěvku
news:XXXX@XXXXX.COM...

>TTabSheet.PageControl property SETS or GETS the TPageControl - (using
>SetPageControl)
>
>MyTabSheet.PageControl := SomePageControl;
>MyTabSheet.PageControl := nil;


Yes, that is probably the best way how to do it. I just wonder if there is
a
source code for standard TPageControl component editor available. I did
the
search but found none.


Best regards,
Ivo