【问题标题】:Delphi Prism: How to access control(s) on a mainform from another form to update its properites?Delphi Prism:如何从另一个窗体访问主窗体上的控件以更新其属性?
【发布时间】:2011-10-07 12:32:07
【问题描述】:

我查看了一个非常相似的 stackoverflow 问题,但答案对我没有帮助。

Updating textbox on mainform with a variable on a child form that is launched from main form

假设我在 Mainform 上有一个 TLabel,我有 winform A 和 B。Winform B 是从 winform A 启动的。如何从 winform B 访问 mainform 上的 TLabel 以更新其(例如)Text 属性?

提前致谢。

【问题讨论】:

  • 您是否可以从FormB 访问MainForm
  • @DavidHeffernan,是的,我愿意。我可以调用它的命名空间和它的 winform 类,但是我可以访问运行程序时显示的 mainform 实例吗?
  • 由于您永远只有一个主窗体,因此您可以轻松地将其设为全局窗体。我想还有很多其他方法可以抓住它。

标签: .net winforms controls delphi-prism


【解决方案1】:

在Program.pas中,创建静态主winform如下:

  Program = assembly static class
  private
    class method OnThreadException(sender: Object; e: ThreadExceptionEventArgs);
  public
    class var lMainForm:MainForm;
    class method Main(args: array of string);
  end;

在 Main 方法中执行以下操作:

[STAThread]
class method Program.Main(args: array of string);
begin
  Application.EnableVisualStyles();
  Application.SetCompatibleTextRenderingDefault(false);
  Application.ThreadException += OnThreadException;
  lMainForm := new MainForm;  
  Application.Run(lMainForm);
end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 1970-01-01
    • 2012-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多