Delphi onshow主窗体/模态窗体 [英] Delphi onshow main form / modal form

查看:976
本文介绍了Delphi onshow主窗体/模态窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个主要形式和其他形式的项目。
当应用程序加载时,需要执行一些任务,并以主窗体顶部的形式显示结果。
我遇到的问题是,如果我调用函数来执行任务/创建,并在主窗体中显示模态窗体,这个窗体出现,但主窗体不会直到模态窗体关闭,这是我预期会发生的。为了解决这个问题,我在主窗体中添加了一个计时器,并在主窗体上显示事件,定时器调用该函数来执行任务/创建并显示模态窗体。所以现在主窗体出现在模态窗体之前。



然而,我看不到这是最好的解决方案,并且想知道是否有人能提供更好的解决方案。



我正在使用Delphi 7



Colin

解决方案

一个常用选项是在窗体的 OnShow 中发布一条消息。像这样:

  const 
WM_SHOWMYOTHERFORM = WM_USER + 0;

type
TMyMainForm = class(TForm)
procedure FormShow(Sender:TObject);
protected
procedure WMShowMyOtherForm(var Message:TMessage);消息WM_SHOWMYOTHERFORM;
结束

...


程序TMyMainForm.FormShow(发件人:TObject);
begin
PostMessage(Handle,WM_SHOWMYOTHERFORM,0,0);
结束

程序TMyMainForm.WMShowMyOtherForm(var Message:TMessage);
开始
继承;
with TMyOtherForm.Create(nil)do begin
try
ShowModal;
终于
免费;
结束
结束
结束


I have a project which has a main form and some other forms. When the app loads it needs to carry out some tasks and show the results in a modal form on top of the main form. The problem I have is that if I put the call to the function to do the tasks / creates and Show the modal form in the main forms onshow event the modal form appears but the main form does not until the modal form is closed, which is what I would expect to happen. To counter this I have added a timer to the main form and start it on the main forms onshow event the timer calls the function to do the tasks / create and show the modal form. So now the main form appears before the modal form.

However I cannot see this being the best solution and was wondering if anyone could offer a better one.

I am using Delphi 7

Colin

解决方案

One commonly used option is to post yourself a message in the form's OnShow. Like this:

const
  WM_SHOWMYOTHERFORM = WM_USER + 0;

type
  TMyMainForm = class(TForm)
    procedure FormShow(Sender: TObject);
  protected
    procedure WMShowMyOtherForm(var Message: TMessage); message WM_SHOWMYOTHERFORM;
  end;

...


procedure TMyMainForm.FormShow(Sender: TObject);
begin
  PostMessage(Handle, WM_SHOWMYOTHERFORM, 0, 0);
end;

procedure TMyMainForm.WMShowMyOtherForm(var Message: TMessage);
begin
  inherited;
  with TMyOtherForm.Create(nil) do begin
    try
      ShowModal;
    finally
      Free;
    end;
  end;
end;

这篇关于Delphi onshow主窗体/模态窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆