Howto free tabssheets

Hi.

And thanks for all the help I have recived here !
Hope you guys can help me with another "problem"

I have created many tabsheets on a pagecontrol at runtime.
Now I want to delete them with a selection on a popupmenu.

I tried this code:

procedure TForm1.Logoffallsessions1Click(Sender: TObject);
var f:integer;
begin
f:=0;
for f:=0 to pagecontrol1.pagecount-1 do
begin
pagecontrol1.pages[f].Free;
end;
end;

but it ends with a error message.

I have tried to switch to another tab/page before freeing it, but that will not work when there are only one page left to close/free.

Ideas?

Comments

  • : Hi.
    :
    : And thanks for all the help I have recived here !
    : Hope you guys can help me with another "problem"
    :
    : I have created many tabsheets on a pagecontrol at runtime.
    : Now I want to delete them with a selection on a popupmenu.
    :
    : I tried this code:
    :
    : procedure TForm1.Logoffallsessions1Click(Sender: TObject);
    : var f:integer;
    : begin
    : f:=0;
    : for f:=0 to pagecontrol1.pagecount-1 do
    : begin
    : pagecontrol1.pages[f].Free;
    : end;
    : end;
    :
    : but it ends with a error message.
    :
    : I have tried to switch to another tab/page before freeing it, but that will not work when there are only one page left to close/free.
    :
    : Ideas?
    :
    [Code]procedure TForm1.Logoffallsessions1Click(Sender: TObject);
    var
    f : integer;
    begin
    for f:=0 to pagecontrol1.pagecount-1 do
    begin
    pagecontrol1.pages[0].Free;
    end;[/Code]

    If you had 5 pages and deleted 0,1 and 2 pagecontrol1.pagecount-1 would be evaluated each time and the next time around it would be 3-1 (only three pages left max index of 2) but your 'j' would have incremented to 3 and would be looking for index page 3.

  • : : Hi.
    : :
    : : And thanks for all the help I have recived here !
    : : Hope you guys can help me with another "problem"
    : :
    : : I have created many tabsheets on a pagecontrol at runtime.
    : : Now I want to delete them with a selection on a popupmenu.
    : :
    : : I tried this code:
    : :
    : : procedure TForm1.Logoffallsessions1Click(Sender: TObject);
    : : var f:integer;
    : : begin
    : : f:=0;
    : : for f:=0 to pagecontrol1.pagecount-1 do
    : : begin
    : : pagecontrol1.pages[f].Free;
    : : end;
    : : end;
    : :
    : : but it ends with a error message.
    : :
    : : I have tried to switch to another tab/page before freeing it, but that will not work when there are only one page left to close/free.
    : :
    : : Ideas?
    : :
    : [Code]procedure TForm1.Logoffallsessions1Click(Sender: TObject);
    : var
    : f : integer;
    : begin
    : for f:=0 to pagecontrol1.pagecount-1 do
    : begin
    : pagecontrol1.pages[0].Free;
    : end;[/Code]
    :
    : If you had 5 pages and deleted 0,1 and 2 pagecontrol1.pagecount-1 would be evaluated each time and the next time around it would be 3-1 (only three pages left max index of 2) but your 'j' would have incremented to 3 and would be looking for index page 3.
    :
    :

    Or assign the pagecontrol1.pagecount-1 to a variable and use the variable in the for statement.

  • : : : Hi.
    : : :
    : : : And thanks for all the help I have recived here !
    : : : Hope you guys can help me with another "problem"
    : : :
    : : : I have created many tabsheets on a pagecontrol at runtime.
    : : : Now I want to delete them with a selection on a popupmenu.
    : : :
    : : : I tried this code:
    : : :
    : : : procedure TForm1.Logoffallsessions1Click(Sender: TObject);
    : : : var f:integer;
    : : : begin
    : : : f:=0;
    : : : for f:=0 to pagecontrol1.pagecount-1 do
    : : : begin
    : : : pagecontrol1.pages[f].Free;
    : : : end;
    : : : end;
    : : :
    : : : but it ends with a error message.
    : : :
    : : : I have tried to switch to another tab/page before freeing it, but that will not work when there are only one page left to close/free.
    : : :
    : : : Ideas?
    : : :
    : : [Code]procedure TForm1.Logoffallsessions1Click(Sender: TObject);
    : : var
    : : f : integer;
    : : begin
    : : for f:=0 to pagecontrol1.pagecount-1 do
    : : begin
    : : pagecontrol1.pages[0].Free;
    : : end;[/Code]
    : :
    : : If you had 5 pages and deleted 0,1 and 2 pagecontrol1.pagecount-1 would be evaluated each time and the next time around it would be 3-1 (only three pages left max index of 2) but your 'j' would have incremented to 3 and would be looking for index page 3.
    : :
    : :
    :
    : Or assign the pagecontrol1.pagecount-1 to a variable and use the variable in the for statement.
    :
    :
    Or you could use one of these codes:
    [code]
    var
    f : integer;
    begin
    for f:=pagecontrol1.pagecount-1 downto 0 do
    pagecontrol1.pages[f].Free;
    end;
    [/Code]
    [code]
    begin
    while pagecontrol1.pagecount > 0 do
    pagecontrol1.pages[0].Free;
    [/code]
  • Hi.

    I have now tried all of these metodes, and they work.
    The FIRST time at least....

    When I start my program, I create some tabs, and have them deleted.
    I then create some tabs again, and when I the try to delete them, I usually gets some kind off errormessage.
    "List index out of bounds ....."
    and I also got another message, but cant remember it....

    I guess this has something to do with the indexing of the tabs, but I have no idea of how to fix it...

    Any ideas?

    Regards,
    Roald
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories