0

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?

Nazari
  • 438
  • 1
  • 9
  • 20
  • 1
    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_? – Baxter Jan 08 '19 at 02:35
  • Your solution has been fixed the error, yes I want TPanel become child for tapPage. For now when I compile and run application I can't see any panel inside tab sheet, when I'm testing. – Nazari Jan 08 '19 at 03:28
  • @DBBaxter Thanks man, I just add `panelPage->Parent = tapPage; panelPage->show();` to it and its work ;D – Nazari Jan 08 '19 at 04:23
  • On a side note: `tabNumber` needs to be initialized, such as `static int tabNumber = 0;`, And `if (tabNumber >= 1)` should probably be `if (tabNumber < MaxInt)` instead. And you really don't need to `Name` your dynamic objects at all, unless you are planning on using `TComponent::FindComponent()` to find them later on, but that is not code good design. And you don't need to call `Show()` when also using `Visible = true` (in fact, that is basically what `Show()` does internally). – Remy Lebeau Jan 08 '19 at 20:07
  • Thanks for note Remy Lebeau, but the `if (tabNumber < MaxInt)` wont work and I'm planing to use dose object later, I will update the answer with your note. – Nazari Jan 09 '19 at 17:33

1 Answers1

0

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".

Nazari
  • 438
  • 1
  • 9
  • 20