Thoughts from Dan Miser RSS 2.0
# Saturday, May 08, 2004
My article, Replacing TabSheets with Frames is now up on the BDN website. This article summarizes issues that you will likely find when designing an application using TPageControl components. The article presents some background information and solutions to problems by using TFrames, interfaces and inheritance. Give it a look, and leave any comments here (or on the BDN site). Be sure to rate the article, too!

Now might be a good time to subscribe to the Delphi BDN RSS feed, too.

Saturday, May 08, 2004 11:45:00 AM (Central Daylight Time, UTC-05:00)  #    Comments [11] -
Delphi
Tracked by:
http://bbbbbbbbbbcc.com [Pingback]
http://fbbbbbbbbbbbb.com [Pingback]
http://ebbbbbbbbbbbb.com [Pingback]
http://dbbbbbbbbbbbb.com [Pingback]
http://bbbbbbbbbbbbc.com [Pingback]
http://www.dogs.com [Pingback]
http://www.cats.de [Pingback]
http://9nh-information.info/96147360/index.html [Pingback]
http://9ns-information.info/09432093/chocolate-madness-state-college-pennsylvani... [Pingback]
http://9nc-information.info/25249125/index.html [Pingback]
http://9nl-information.info/11028342/index.html [Pingback]
http://9ni-information.info/44873134/index.html [Pingback]
http://9ng-information.info/67072344/index.html [Pingback]
http://9ny-information.info/53873195/world-health-organisation-deutschland.html [Pingback]
http://9nb-information.info/51084435/index.html [Pingback]
http://9ox-information.info/30152231/index.html [Pingback]
http://9qm-information.info/80329814/concepimento-test.html [Pingback]
http://9ot-information.info/81264655/index.html [Pingback]
http://9qe-information.info/33534133/index.html [Pingback]
http://9oj-information.info/15389173/index.html [Pingback]
http://9og-information.info/58323423/kuwait-job-vacancy.html [Pingback]
http://9ou-information.info/70506437/index.html [Pingback]
http://9qn-information.info/58368213/index.html [Pingback]
http://9qs-information.info/26679566/index.html [Pingback]
http://9rr-information.info/04020662/index.html [Pingback]
http://9rl-information.info/74181521/harry-lauder-photo.html [Pingback]
http://9ri-information.info/73378882/index.html [Pingback]
http://9rv-information.info/68282654/lewis-structure-table.html [Pingback]
http://9rc-information.info/58042221/index.html [Pingback]
http://9rk-information.info/34883639/index.html [Pingback]
http://9uafm-le-informazioni.info/04927597/gubbio-medievale.html [Pingback]
http://9uaec-le-informazioni.info/68243926/ambassade-belge.html [Pingback]
http://9uaeg-le-informazioni.info/59071602/index.html [Pingback]
http://9uafp-le-informazioni.info/82518715/index.html [Pingback]
http://9uaeh-le-informazioni.info/50688654/mappa-linea-tram-roma.html [Pingback]
http://9uafk-le-informazioni.info/72732009/gabriele-patriarca.html [Pingback]
http://9uaek-le-informazioni.info/11117918/index.html [Pingback]
http://9uafq-le-informazioni.info/84373936/florida-italia.html [Pingback]
http://9uafi-le-informazioni.info/36320190/asl-ce2.html [Pingback]
http://9uaeh-le-informazioni.info/51635044/index.html [Pingback]
http://9uafa-le-informazioni.info/06204580/index.html [Pingback]
http://9uagm-le-informazioni.info/99708418/index.html [Pingback]
http://9uahf-le-informazioni.info/17338082/lourdes-pellegrinaggi.html [Pingback]
http://9uagt-le-informazioni.info/17861460/index.html [Pingback]
http://9uagl-le-informazioni.info/89467790/index.html [Pingback]
http://9uagb-le-informazioni.info/21140013/ricerca-sulla-globalizzazione.html [Pingback]
http://9uagj-le-informazioni.info/20715644/index.html [Pingback]
http://9uaga-le-informazioni.info/16247645/museo-beaux-art-lione.html [Pingback]
http://9uaha-le-informazioni.info/33464170/www-hotel-torino.html [Pingback]
http://9uagf-le-informazioni.info/67775797/la-brava.html [Pingback]
Sunday, May 09, 2004 1:32:00 PM (Central Daylight Time, UTC-05:00)
Great article, Dan. I have to admit, I've been one to use TPageControls just as you described.
Tuesday, May 11, 2004 10:59:00 AM (Central Daylight Time, UTC-05:00)
One useful addition would be a helper method to make sure that the tabsheets are configured correctly.



procedure TSampleForm.LinkTabToFrame(ts:TTabSheet; fc:TBaseFrameClass);

begin

ts.tag := integer(fc);

ts.OnShow := TabSheetShow;

ts.OnHide := TabSheetHide;

end;
Marc Rohloff
Tuesday, May 11, 2004 2:21:00 PM (Central Daylight Time, UTC-05:00)
Thanks, Marc. Hopefully, this won't be needed in the next version of the code and article since I'll just extend the TPageControl and TTabSheet to handle all of this.
Wednesday, May 12, 2004 9:39:00 PM (Central Daylight Time, UTC-05:00)
Very timely article! I'm just about to start a project that is browser-esque in the fact that very few secondary forms are ever shown, instead differents views and pages are loaded which the main form as the parent. I was going to just use a lot of TForm's and set their Owner to the mainform but I have a feeling TFrames and a TPageSheet method will work much better.



I'd love to see any improvements\enhancements on this method. Thanks for sharing.



Shawn Oster
Wednesday, May 12, 2004 9:49:00 PM (Central Daylight Time, UTC-05:00)
One more thing...



I know this is an example but I noticed you code in a slightly more .NET way in terms of your naming style. You have lowercase local variables, a la C#\.NET, while the 'Delphi' way is first-letter upppercase.



Not being picky, I'm actually struggling with switching back and forth myself. Do I use one style per language or do I try and use the same style for both?
Shawn Oster
Tuesday, May 18, 2004 6:38:00 AM (Central Daylight Time, UTC-05:00)
Great, just what I was looking for!



Some doubts about the GetFrame function though:



1. The first if-statemen, "if not Assigned(.." doesn't make much sense if the ATabsheet doesn't have a default value of nil.

2. The second if-statement starts with "if Assigned(.. which seems redundant as we just tested for "not Assigned" and took appropriate action.

3. Furthermore this if-statement will cause an exeption if there are no controls present and the last and-part is executed before the second. (AFAIK Delphi does not guarantee the order of testing for "and" conditions.)



So my version of the function would be:



function TSampleForm.GetFrame(ATabSheet: TTabSheet=nil): TFrame;

begin

if not Assigned(ATabSheet) then

ATabSheet := PageControl.ActivePage;

Result := nil;

if ATabSheet.ControlCount > 0 then

if ATabSheet.Controls[0] is TFrame then

Result := TFrame(ATabSheet.Controls[0]);

end;
Tuesday, May 18, 2004 2:51:00 PM (Central Daylight Time, UTC-05:00)
Thanks for the feedback, Jan. To address your comments:

1. You can still call GetFrame(nil) to get the frame for the active page. As a matter of fact, I left it this way intentionally so that you always had to explicitly state what tabsheet you were after. I can see some benefit to adding the optional param, though.

2. Redundant, yes. It's also defensive. What happens if PageControl.ActivePage returns nil?

3. The if statement is fine. Due to short-circuit boolean evaluation, if any part of the if statement evaluates to false, the next part of the if statement doesn't execute.



So, in summary, it appears that perhaps an optional parameter could be added, but the rest is fine.
Wednesday, May 19, 2004 2:49:00 AM (Central Daylight Time, UTC-05:00)
Point 1 is maybe mostly a question of programming standards. Neither the alternative "GetFrame" nor "GetFrame(nil)" make much sense logically when what one wants to say is something like "GetFrame(CurrentPage)". Neither of the two alternatives is intuitively easier to understand when maintaining the code but I think the parameterless form is the more common solution. No big deal anyway!

Point 2: Your solution is of course the right one!

Point 3: Still a bit confused. Can we safely assume left-to-right evaluation in Delphi?.



As an aside, I now have my first conversion of an application to utilize your PageControl/Frames setup up and running. What a relief to get rid of that 2000+ lines unit that now is split into 5 different units. Just doing the conversion allowed me to get rid of a lot of redundancies and duplications that had crept into the code and made it almost unmaintainable.
Sunday, September 05, 2004 12:29:00 PM (Central Daylight Time, UTC-05:00)
Perfect article. I want to convert my editor application which craetes dynamicly tabsheets in the pagecontrol. How do I dynamicly create the frames (TBaseFrame) and then assign these to the tabsheets.

Any hints are most welcome,

Robert Linn (Hamburg - Germany)
Robert Linn
Thursday, September 09, 2004 10:34:00 AM (Central Daylight Time, UTC-05:00)
Both the sample code, and Marc's comment above should show you how to assign the frames to the tabsheet. The article also covers this showing how to assign the class reference to the TabSheet.Tag property.



Or did I not understand what you were asking?
Thursday, November 23, 2006 7:19:00 AM (Central Standard Time, UTC-06:00)
Dan, sorry for my english es very poor.

When I declare TFrameClass = class of TFrame; leaves then following message "Fatal Error: Requiered Package Teeimage not found, as I solve this?. Tanks
Pablo Sangenis
Comments are closed.
Navigation
Archive
<February 2012>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2012
Dan Miser
Sign In
Statistics
Total Posts: 375
This Year: 3
This Month: 0
This Week: 0
Comments: 654
Themes
Pick a theme:
All Content © 2012, Dan Miser
DasBlog theme 'Business' created by Christoph De Baene (delarou)