开发者

problems opening a form with a predefined tabsheet

开发者 https://www.devze.com 2023-01-16 10:20 出处:网络
The following code works ! with pagecontrol1 do begin case Myindex of 0: activep开发者_如何学JAVAage := tabsheet1;

The following code works !

with pagecontrol1 do
begin
  case Myindex of
    0: activep开发者_如何学JAVAage := 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 ?


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;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号