I have a problem getting the tabPage->Name
value, because it will generate when user click the button, first block of my code will create new tabsheet inside PageControl3
and then I use the static int tabNumber;
by if
condition to generate the tabPage->Caption
and then I use the caption for tabPage->Name
dynamically.
I need the name of that tabsheet to pass it on the Error line.
static int tabNumber;
if (tabNumber >= 1) ++tabNumber;
else tabNumber = 1;
PageControl3->Visible = true;
TTabSheet *tabPage = new TTabSheet(PageControl3);
tabPage->PageControl = PageControl3;
tabPage->Caption = UnicodeString("Untitled") + IntToStr(tabNumber);
tabPage->Name = UnicodeString("ts") + tabPage->Caption;
The second part of my code should create new TPanel
inside current tabpage->Name
that was created in the above part of my code, BUT it wont work.
TPanel *panelPage = new TPanel(tabPage->Name); // Error Line
panelPage->Align = alClient;
panelPage->Name = UnicodeString("panel") + tabPage->Caption;
Error massage:
[bcc32 Error] mainUnit.cpp(50): E2285 Could not find a match for 'TPanel::TPanel(const UnicodeString)'
So I not know how to access the tabPage->Name
value, because that was create dynamically?
DB Baxter The constructor requires a component variable/object and not a string with the text of the name. Such as TPanel *panelPage = new TPanel(tabPage); Will that work for you? Do you need to make the panel's parent tabPage?
By helping DB Baxter, I think the correct and complete answer for create dynamic TPanel
inside the dynamic TTabSheet
will requires a component variable/object and then for displaying the TPanel
we should use the whatever->show();
command, the full code can bee like this:
static int tabNumber = 0;
if (tabNumber >= 1) {
++tabNumber;
} else {
tabNumber = 1;
PageControl3->Visible = true;
}
// create new tab sheet inside PageControl3
TTabSheet *tabSheet = new TTabSheet(PageControl3);
tabSheet->PageControl = PageControl3;
tabSheet->Caption = UnicodeString("Untitled") + IntToStr(tabNumber);
tabSheet->Name = UnicodeString("ts") + tabSheet->Caption;
// create new panel inside the current tab sheet
TPanel *panelBox = new TPanel(tabSheet);
panelBox->Parent = tabSheet;
panelBox->Align = alClient;
panelBox->Name = UnicodeString("panelPage") + IntToStr(tabNumber);
panelBox->BevelOuter = bvNone;
panelBox->ShowCaption = true;
panelBox->Caption = UnicodeString("panel") + tabSheet->Caption;
panelBox->Show();
I hope this code can help anyone to generate the dynamic tab sheet with panel, by the way if you want add some frame to it the following code should use:
// adding the registration frame to the panel
TregFrame *newRegistration = new TregFrame(panelBox);
newRegistration->Parent = panelBox;
newRegistration->Align = alClient;
Note: don't forget to include your frame in your working file, for example #include "registrationFrame.h"
.