Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic creation of components

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
I'm working on a comprehensive case inquiry program. This application finds all the information regarding a case and displays it. For instance, I have a PageControl with the following:
Demographics
Charges
Events
Payments
Summons/Warrants
Bonds
Tape Log
File Location
Community Service
Educational Services

I run a basic query and if there's any information for that "section" then the tabvisible property for the specific information is determined.

Now I'm working on the Educational Services tab. There are about 15 classes that a defendant can be sentenced to and what I wanted to do was add a tabbed page for each of the classes.

So, if the defendant was sentenced to any Educational Services programs the first tab (SENTENCING) would show:

Victim Impact Panel + other info
Screening + other info
Ed Services Referral + other info
A.S.P.E.N. + other info

then I would like 4 additional tabs - one for each of the classes listed above.

I have successfully done this, but now, how do I create the information on the page? Do I need a "page template"? Most of the classes have similar information (some have more than 1 class date), how can I dynamically create the page based on what kind of class it is?

Thanks for any insight.

Leslie
 
OK, I've run into some difficulty here.

I've determined that a TabControl isn't what I want. I need a second PageControl.

So I have PageControl1 with the above (Demographics, Charges, etc.) tabs set up. I have added PageControl2 to the Educational Services tabsheet from PageControl1. However, the second PageControl DOES NOT APPEAR when I run the program. I can see it fine in design mode, I have added a dbGrid to one of the tabSheets and it all looks good in the editor, but when I run the application, there is NOTHING on the Educational Services TabSheet.

Can I not have a second PageControl or can I just not have it on a tabSheet on an existing PageControl?

Thanks!
 
You can have nested pagecontrols. We have some nested 3 levels deep that work properly.

Do you have the tabs set to tabvisible := false?

Is it possible that the second page control is not really inside one of the tabs, but resting on top of it?

Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
No, the tabvisible is set to TRUE

Looking at the treeview, it appears that PageControl2 is actually on the TabSheet, when I view form as text, it also looks like it's on the tabsheet. I've even added a panel to the Educational Services tabsheet and then put the second PageControl in the panel, but that didn't work either.

Really odd!

Thanks for the suggestions, I'll keep working on it!

Leslie


 
I almost forgot about it until now, but we ran into something like this a couple weeks ago (someone else on the team) and he ended up deleting the page controls and recreating them. The problem resolved itself when he switched pages, but on formshow the interior pagecontrol was not visible.

Can you test the status using a showmessage at runtime?:

if PageControl2.Visible = true then
showmessage('Visible');


Does it work if you refer programatically to the pagecontrol?

What happens if you do something like this:

PageControl2.Visible := true;
PageControl2.ActivePage := tabsheet1;


Brian
"There are 2 kinds of people in the world, those that divide people into two groups and those that don't. I belong to the second group." - tag line I stole
 
When I have a lot of tabs, and/or dynamically changing tabs I have a separate form for each page

Use a TTabControl instead of a TPageControl.

The biggest advantage is that you don't end up with one huge unmanageable source file.

Use the OnChange event of the TTabControl to create the pages. Code like:

case (TabControl1.TabIndex)of
0:FCurrentPage:=TPageForm1.Create(Self);
1:FCurrentPage:=TPageForm2.Create(Self);
else Exit;
end;


with FCurrentPage do begin
Parent:=TabControl1;
BorderStyle:=bsNone;
Align:=alClient;

DataSource1:=...........

Visible:=true;
end;

An free them on OnChanging

if(FCurrentPage<>nil)then begin
FCurrentPage.DataSource1.Dataset.CheckBrowseMode;
Any other saving code..............

FreeAndNil(FCurrentPage);
end;

You can cache the pages by making FCurrentPage an array and checking fo existance of the relevant page on OnChange and making it visible or creating as appropriate.

Have fun
Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top