Delphi 2010 如何在表单启动时执行某些操作而不需要用户执行某些操作(按钮单击等..)

发布于 2024-12-22 11:18:59 字数 332 浏览 2 评论 0原文

如何在表单启动时执行某些操作,例如:

  RichEdit1.Lines.Add('sorry [email protected] is already in our database');

直到用户采取某些操作(单击按钮等...)

我尝试使用下面的代码并且它有效,但我必须单击按钮一以便将该行添加到richEdit1 组件。

How to do something on form startup like :

  RichEdit1.Lines.Add('sorry [email protected] is already in our database');

NOT untill the user take some action ( Button click, etc..)

I tried with the code below and it works but i am obliged to click on the button one in order to add that line into the richEdit1 compenent.

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

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

发布评论

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

评论(4

时光是把杀猪刀 2024-12-29 11:18:59

您可以使用表单的OnActivate 事件来设置可视控件的属性。我通常这样做:

procedure TForm1.FormActivate(Sender: TObject);
begin
  //Allow this code to run only once
  OnActivate := nil;

  //Set RichEdit Properties
  RichEdit1.Lines.Add('sorry [email protected] is already in our database');
end;

You can use the OnActivate event of the form to set properties for visual controls. I usually do it as follows:

procedure TForm1.FormActivate(Sender: TObject);
begin
  //Allow this code to run only once
  OnActivate := nil;

  //Set RichEdit Properties
  RichEdit1.Lines.Add('sorry [email protected] is already in our database');
end;
平安喜乐 2024-12-29 11:18:59

如果在设计时已将 TRichEdit 控件添加到窗体中,则可以在窗体的 OnCreate 事件中设置 RichEdit 控件的属性。

这允许您在用户看到控件或有机会与它们交互之前设置控件的属性。

OnCreate 在创建表单(包括子控件)之后和显示之前调用。

要打开 OnCreate 事件以在 IDE 中进行编辑,只需双击表单的空白部分即可。

If the TRichEdit control has been added at design time to a form, then you can set the properties of the RichEdit control in the form's OnCreate event.

This allows you to set the properties of controls before the user even sees the controls or has a chance to interact with them.

OnCreate is called after the form is created (including child controls) and before it's shown.

To open the OnCreate event for editing in the IDE, you can simply double-click on an empty part of the form.

顾冷 2024-12-29 11:18:59

使用窗体的 OnShow 事件。

但是:使用私有字段 FShown :布尔值,并在 OnShow 处理程序中测试它 - 如果它是 TRUE,则立即退出。

如果为 FALSE,则将其设置为 TRUE 并继续执行您想做的任何操作。

还有 OnCreate 事件,但在许多情况下还为时过早 - 当 OnCreate 处理程序中的代码运行时,许多可视组件尚未正确初始化。

Use the OnShow event of the form.

BUT: use a private field FShown : boolean, and test it in your OnShow handler - if it is TRUE, exit immediately.

if it is FALSE, then set it to TRUE and proceed with whatever you want to do.

There's also the OnCreate event, but in many cases that is too early - many visual components have not been properly initialized yet when code in OnCreate handler is running.

似狗非友 2024-12-29 11:18:59

有时,有必要延迟操作直到消息循环开始运行。在这些情况下,我倾向于使用表单的构造函数或 OnCreate 事件通过 PostMessage() 向表单窗口发布自定义异步消息(有些人使用短间隔TTimer 代替),然后在收到消息时在表单的 WndProc() 方法中执行操作。

Sometimes, it is necessary to delay actions until the message loop has started running. In those situations, I tend to use the form's constructor or OnCreate event to post a custom asynchronous message to the form's window via PostMessage() (some people use a short-interval TTimer instead), and then perform the action in the form's WndProc() method when the message has been received.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文