softtouch 9 Posted October 24 (edited) I need to modify forms the moment they are created, before they are shown. And there are many forms, so i cant use the onCreate event. I know I can check the Screen.Forms[], but I would like to use an event, so the code to check the forms array is only called when needed. Is this somehow possible? I currently use such test code: var i:Integer; begin Result := nil; for i := 0 to Screen.FormCount - 1 do begin if Screen.Forms[i].Handle = AHandle then begin Result := Screen.Forms[i]; break; end; end; end; begin if (Msg.message = WM_DWMNCRENDERINGCHANGED) then begin f := GetFormByHandle(Msg.hwnd); if Assigned(f) then begin // Process form here end; end; end; I know the WM_DWMNCRENDERINGCHANGED is not made for this, but it at least seems to work. I was hoping there is a proper way to do that, but I had no luck to find anything related. Edited October 24 by softtouch Share this post Link to post
JonRobertson 70 Posted October 24 13 minutes ago, softtouch said: I need to modify forms on the fly, the moment they are created I would use Visual Form Inheritance for this, and place the "process form here" logic in the base form. If that isn't ideal, please give a better description. "modify forms on the fly" and "modify forms the moment they are created" are not the same. If you want to use an event, you could add a new event to your base form and implement the event in each derived form. You'd need to figure out when to assign the event so it would be executed by the base form's code when each form is created. I can think of a couple options, depending on your actual use case. Share this post Link to post
PeterBelow 238 Posted October 25 14 hours ago, softtouch said: I need to modify forms the moment they are created, before they are shown. And there are many forms, so i cant use the onCreate event. I know I can check the Screen.Forms[], but I would like to use an event, so the code to check the forms array is only called when needed. Is this somehow possible? I Perhaps you can use the Screen.OnActiveFormChange event for this. But keep in mind that it is not only called when a new form is shown but also when focus changes between forms. It may also happen too late for your purpose. Share this post Link to post