Delphi Prism: How to access control(s) on a mainform from another form to update its properites?

221 views Asked by At

I have looked at a very similar stackoverflow question(s), but the answers aren't helping me.

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

Say I have a TLabel on the Mainform and I have winform A and B. Winform B is launched from winform A. How do you get access to the TLabel on mainform from winform B to update its (say) Text property?

Thanks in advance.

1

There are 1 answers

0
ThN On BEST ANSWER

In Program.pas, create static main winform as follows:

  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;

In Main method do the following:

[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