0

My Delphi application initially starts by showing the main form, but with a user login panel only. I hide the main menu, so that the unauthenticated user is not able to access it. Upon user login, I dynamically assign the menu by setting Form.Menu := MyMainMenu;.

However, when the user logs in, and I assign the main menu as mentioned, it isn't immediately visible until the form is resized in some way. Minimizing the window and showing it again also triggers the main menu to show. However, I need it to show right away when I assign it.

I have tried adding the following attempts just after assigning the main menu, but makes no difference:

Self.Repaint;
Self.Refresh;
Application.ProcessMessages;

The only thing I can do is to slightly resize the form in run-time, then it triggers it to show. However, not only is this sloppy, but my application shows in the Maximized state by default.

Note: I am using VCL Styles. Without styles, it shows just fine. Trying Vcl-Styles-Utils and its fixes does not make a difference.

How do I get the newly assigned main menu to immediately show without a "resize" hack?


On a side note, when I close the application, I have a memory leak: Memory leak from VCL Styles on the Main Menu

Without VCL Styles, this memory leak doesn't occur. Not that I'm asking for a solution for that, but an additional symptom which might help identify the root issue.

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • In my older version, style menu initialization is triggered while the menu style hook handles WM_NCCALCSIZE sent for the form. For a least intrusive way of generating one (e.g. without modifying the size), see documentation for SetWindowPos. – Sertac Akyuz Jun 20 '20 at 01:19
  • @Sertac Yeah, I was just starting to realize it's an NC issue - now that I'm trying to implement Vcl-Style-Utils NC buttons, and facing similar issues. The Non-Client region doesn't want to update immediately. I need to force it. – Jerry Dodge Jun 20 '20 at 01:21
  • Why not just use a completely different Form for the user login? You can display and close a separate Form before the MainForm is even created. Just don't use `Application.CreateForm()` for the login Form, unless you create it after the MainForm is created first. The MainForm does not have to be *shown* right away. – Remy Lebeau Jun 20 '20 at 02:25
  • @Remy Full-screen kiosk-like experience. – Jerry Dodge Jun 20 '20 at 02:34
  • 2
    I fail to see the reason for not using a separate form in a kiosk-like application. However, did you try `SetWindowPos(Form.Handle, 0, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE or SWP_NOZORDER or SWP_NOACTIVATE or SWP_FRAMECHANGED)` just after `Form.Menu := MyMainMenu;`? – Sertac Akyuz Jun 20 '20 at 03:32
  • @Sertac That seems to do the trick, forcing the NC area to repaint. – Jerry Dodge Jun 20 '20 at 15:40

0 Answers0