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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

renaming tabsheet caption after destroy

Status
Not open for further replies.

rtb1

IS-IT--Management
Jul 17, 2000
73
ES
Hi,

I have a PageControl with dynamically added tabsheets. The caption looks like: Page 1, Page 2, Page 3, etc.

It is also possible to destroy a tabsheet.This is simply done with:

PageControl1.ActivePage.Destroy;

The problem now is that the captions need to be renamed so you still see: Page 1, Page 2, Page 3, etc.

I can't figure out a good routine that looks at the number of tabsheets and then renames the caption of each like described above.

Anyone can help me with this?

Thanks,
Raoul
 
I would not rename the actual tabsheets, just the captions. You can easily get from page to page using the PageCount and Pages properties of your TPageControl. Something like this:
Code:
for i := 0 to (PageControl1.count - 1) do
  PageControl1.pages[i].Caption := format('Page %d', [i]);
application.processmessages; //causes the changes to appear on the screen

-Dell
 
Hi. Try this...
Code:
procedure TForm1.Button1Click(Sender: TObject);
var
  PageNo, i: Integer;
begin
  PageNo := PageControl1.ActivePageIndex;
  PageControl1.ActivePage.Destroy;
  for i := PageControl1.PageCount -1 downto PageNo do
    PageControl1.Pages[i].Caption := 'Page '+IntToStr(i);
end;

//Nordlund
 
With any object you should use the Free method rather than Destroy. Here's an excerpt from the Delphi help:
Destroys an instance of TTabSheet.

destructor Destroy; override;

Description

Do not call Destroy directly at runtime. Instead, call Free. Free verifies that the tab sheet is not nil and only then calls Destroy. Destroy removes the tab sheet from the page control and then calls the inherited Destroy method.

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Thanks to all,

Using free now instead of destroy and:

Code:
for i := 0 to (PageControl1.PageCount - 1) do
  PageControl1.pages[i].Caption := 'Page '+IntToStr(i);
 
Just a minor and rather obvious point: you originally said your page captions began at 1 (i.e. Page 1, Page 2, etc.). If this is still the case then you need to use "i + 1" in the IntToStr function, otherwise your pages will run from 0 (i.e. Page 0, Page 1 etc.) which will look a bit odd!

Clive [infinity]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer."
Paul Ehrlich
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top