tags:

views:

104

answers:

1

The following code works !

with pagecontrol1 do
begin
  case Myindex of
    0: activepage := tabsheet1;
    1: activepage := tabsheet2;
    2: activepage := tabsheet3;
  end;
end;
show;

The following code does not work

with pagecontrol1 do
begin
  case Myindex of
    0: activepage := tabsheet1;
    1: activepage := tabsheet2;
    2: activepage := tabsheet3;
  end;
end;
showmodal;

how to solve this ?

A: 

the problem was when I create a new form in runtime, and set active page before I use showmodal, the command seem to be ignored, however if I show it as normal "show" it works.

I made a workaround for this for people interrested by using a postmessage so the command can be triggered after the modal form is shown.

...
private
    Procedure WM_UserPage(var Msg: TMessage); message WM_USER+1;
...

procedure TForm2.UserPage(var Msg: TMessage);
begin
  with pagecontrol do
  case Msg.LParam of
    0: activepage := tabsheet1;
    1: activepage := tabsheet2; 
    2: activepage := tabsheet3; 
  end;
end;

from my first form I call : 

procedure TForm1.ShowPage(PageNumber: integer);
var
  MyForm : TForm2;
begin
  MyForm := TForm2.create(self);
  with MyForm do
  try
    PostMessage(MyForm.Handle, WM_USER+1, 0, PageNumber);
    showmodal;
  finally
    FreeAndNil(MyForm);
  end;
end;
Plastkort