Board index » cppbuilder » TPageControl help file example

TPageControl help file example


2003-11-22 09:07:57 AM
cppbuilder41
Here's the example in the Help docs for TPageControl:
#include <Comctrls.hpp>
TPageControl* ppc;
TTabSheet* pts[MAXTABS];
const char * ppcTabTitles[] = { "ShortString", "Orders", "Items", "Parts" };
int iTabTitles = sizeof(ppcTabTitles)/sizeof(ppcTabTitles[0]);
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ppc = new TPageControl(this);
ppc->Parent = this;
ppc->Align = alClient;
for (int i=0;i<iTabTitles;i++)
{
pts[i] = new TTabSheet(this);
pts[i]->PageControl = ppc;
pts[i]->Name = AnsiString("pts") + ppcTabTitles[i];
pts[i]->Caption = ppcTabTitles[i];
}
}
void __fastcall TForm1::FormDestroy(TObject *Sender)
{
for (int i=0;i<iTabTitles;i++)
delete pts[i];
delete ppc;
}
To begin with, of course, it is using FormCreate and FormDestroy - no-no
in C++Builder. But I also wonder about the deletes. I thought that the
owner was responsible for deleting, so the "new TPageControl(this)" sets
the owner to be the form, and it will be responsible for deleting it.
Isn't that right?
--
Jonathan Arnold C/C++/CBuilder Keen Advice:
www.keen.com/categories/categorylist_expand.asp
Comprehensive C++Builder link site:
www.buddydog.org/C++Builder/c++builder.html
 
 

Re:TPageControl help file example

"Jonathan Arnold" < XXXX@XXXXX.COM >wrote in message
Quote
To begin with, of course, it is using FormCreate and
FormDestroy - no-no in C++Builder.
Correct. But that is becaue most of Borland's examples in the help file are
just translations of the equivilent Delphi code. I don't think the
documentation writers take C++ issues into account when they write the
documentation, so many examples are wrong because of that.
Quote
But I also wonder about the deletes. I thought that the owner
was responsible for deleting
It is. But it is allowed to free an owned object manually. It will simply
remove itself from its Owner's internal lists so that the Owner does not try
to free it again later on.
Quote
so the "new TPageControl(this)" sets the owner to be the form,
and it will be responsible for deleting it.
It will.
Gambit