TForm.ManualDock 应该调用 onFormShow 吗?

发布于 2024-12-20 01:41:48 字数 255 浏览 1 评论 0原文

当我输入这个问题时,我意识到它可能应该如此。

当调用 form.Create() 和调用 form.ManualDock(pagecontrol,pagecontrol.alClient) 时,将表单停靠到 TPageControl 会调用 FormShow。

取消停靠表单也会调用 show,我认为这是因为当您停靠/取消停靠时,表单实际上是“重置”的?

如果这是按照设计的,我将重构我不想在 onCreate 中触发的代码(除非这是糟糕的设计)。

As I typed this question I realize that it probably should.

Docking a form to a TPageControl calls FormShow when form.Create() is called and when form.ManualDock(pagecontrol,pagecontrol.alClient) is called.

Un-docking the form also calls show and I assume this is because the form is actually 'reset' when you dock/undock?

If this is as designed I'll just refactor the code I dont want to fire there to onCreate (unless that is bad design).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

長街聽風 2024-12-27 01:41:48

是否应该更多的是哲学问题而不是技术问题。 TForm.OnShow 事件由执行控制消息 CM_DOCKCLIENT 也使用通过 ManualDock 函数。在内部,此消息调用 CM_SHOWINGCHANGED 触发事件本身。

在下面的示例中,我将使用两个表单:Form1(带有页面控件和按钮)和 Form2(空且可停靠)。我认为两者都是自动创建的。

下面的代码证明了 OnShow 事件由 CM_DOCKCLIENT 控件触发 信息。单击该按钮,将执行 CM_DOCKCLIENT 消息和 Form2 的 OnShow事件被触发。

Form1

procedure TForm1.FormShow(Sender: TObject);
begin
  Form2.Show;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  DockObject: TDragDockObject;
begin
  DockObject := TDragDockObject.Create(Form2);
  try
    // sending the CM_DOCKCLIENT message internally performs also the
    // CM_SHOWINGCHANGED message which triggers the TForm.OnShow event
    PageControl1.Perform(CM_DOCKCLIENT, WPARAM(DockObject), LPARAM(SmallPoint(0, 0)));
  finally
    DockObject.Free;
  end;
end;

和 Form2 的代码只有 OnShow 事件处理程序

procedure TForm2.FormShow(Sender: TObject);
begin
  ShowMessage('FormShow');
end;

一个简单的解决方法是不要手动停靠 Form2(在 OnShow 事件),但由创建者停靠它,或者说通过显示它的表单。在前面的示例中,我在 Form1.OnShow 事件中显示了 Form2,因此我可以轻松地将其手动停靠在那里。

procedure TForm1.FormShow(Sender: TObject);
begin
  Form2.Show;
  Form2.ManualDock(PageControl1);
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  // no manual docking of this form by itself
end;

If should or not is more philosophical than technical question. The TForm.OnShow event is fired by performing control message CM_DOCKCLIENT which is used also by the ManualDock function. Internally this message calls the CM_SHOWINGCHANGED what fires the event itself.

In the following example I will use two forms, Form1 (with a page control and a button) and Form2 (empty and dockable). I presume that both are auto created.

The following code is a proof that the OnShow event is fired by the CM_DOCKCLIENT control message. Clicking on the button, the CM_DOCKCLIENT message is performed and Form2's OnShow event is fired.

Code for Form1

procedure TForm1.FormShow(Sender: TObject);
begin
  Form2.Show;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  DockObject: TDragDockObject;
begin
  DockObject := TDragDockObject.Create(Form2);
  try
    // sending the CM_DOCKCLIENT message internally performs also the
    // CM_SHOWINGCHANGED message which triggers the TForm.OnShow event
    PageControl1.Perform(CM_DOCKCLIENT, WPARAM(DockObject), LPARAM(SmallPoint(0, 0)));
  finally
    DockObject.Free;
  end;
end;

And Form2 has only the OnShow event handler

procedure TForm2.FormShow(Sender: TObject);
begin
  ShowMessage('FormShow');
end;

An easy workaround is not to dock the Form2 manually by its own (in the OnShow event) but dock it by the creator or let's say by the form which displays it. In my previous example I've displayed the Form2 in the Form1.OnShow event, so I can easily dock it manually there.

procedure TForm1.FormShow(Sender: TObject);
begin
  Form2.Show;
  Form2.ManualDock(PageControl1);
end;

procedure TForm2.FormShow(Sender: TObject);
begin
  // no manual docking of this form by itself
end;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文