简体   繁体   English

Delphi Prism:如何在不显示Winform的情况下加载它?

[英]Delphi Prism: How to load Winform without showing it?

I have a winform that needs to be loaded to update its controls' values or properties, before it is to be shown. 我有一个Winform,必须先加载它才能更新其控件的值或属性,然后再显示它。

I found a stackoverflow question asking the same thing, but it's answer doesn't really help me. 我发现一个stackoverflow问题问同样的事情,但是它的回答并没有真正帮助我。 Load a form without showing it 加载表单而不显示它

Any sample code will be appreciated. 任何示例代码将不胜感激。 Thank you, 谢谢,

Only you need create a new instance of the form and set the values of the controls. 仅您需要创建表单的新实例并设置控件的值。

check this code 检查此代码

Var
  AForm : ChildForm;
begin
  AForm:= new ChildForm;
  AForm.textBox1.Text:='Foo';  //this control can be accessed here  because the Modifiers property was set to public. 


  AForm.Show;
end;

Btw remember if you want modify or access the controls of another form you must set the property Modifiers of the control to access to public . 记住,如果要修改或访问其他表单的控件,则必须将控件的属性“ Modifiers ”设置为可访问public

Create the form like this: 创建如下形式:

form := new MyForm();

Assuming you have implemented a method on MyForm to update the values, call it: 假设您已经在MyForm上实现了一种方法来更新值,请调用它:

form.Update();//may need to pass parameters here

Show the form in the usual way: 以通常的方式显示表格:

form.ShowDialog();

From MSDN: 从MSDN:

Form.Load Form.Load
Occurs before a form is displayed for the first time. 在第一次显示表单之前发生。

So you can do all updates to the controls that are necessary before you show the form in this event handler. 因此,您可以在此事件处理程序中显示表单之前,对控件进行所有必要的更新。

But actually it is probably better to use databinding on the controls, so that they automatically reflect the current values you want them to show and you don't have to write any glue code bringing data on controls (and reading from them). 但是实际上,最好在控件上使用数据绑定 ,以便它们自动反映您希望它们显示的当前值,而您不必编写任何胶合代码即可将数据带到控件上(并从控件中读取数据)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM