TFrame in a TForm, events disappear.. lazarus / 31-LCL ---------------------------------------------------------------------- julgus · 2016-10-14 09:59 I have got a form and a part of the form is a frame. Works great. But my defined events in the frame isn't working when I try using them in the form? Why? When I check the event for an object in the frame in my form the event is blank, I thought it to be the defined frame event... ---------------------------------------------------------------------- howardpc · 2016-10-14 11:07 The attached project shows how both internal frame events (i.e. events of frame-contained controls) should be hooked up (OnTimer, OnSelectionChange), and how an external frame property (Enabled) can be manipulated by an event. The events were all set via the Events page of the Object Inspector, but they can of course also be set in code. If you still want help with your code you will need to share a compilable example that does not work as you want it to. ---------------------------------------------------------------------- julgus · 2016-10-14 11:25 Thanks! I thought that if I made a change in a the Frame it would automatically change in the forms where I used the frame. It seems just to copy the design into the form. Is there a method where I can get a frame change replicated into the forms where it's used? ---------------------------------------------------------------------- howardpc · 2016-10-14 15:03 For me changes to a frame unit are generally reflected in forms that use them when I recompile. If for some reason they are not, try a build (Run -> Build) or a cleanup build (Run -> Clean up and Build) rather than just a compile (F9) after making changes. ---------------------------------------------------------------------- Relativity · 2021-05-20 09:09 I am experimenting a bit with forms, inherited forms and frames. I have a frame with a button and the method managing the event of clicking the button. The frame is embedded in a form. But the event does not work. Apparently the method managing the click is not executed at all. I wanted to ask if anybody can take a look at this code and tell me why the button "Button1" does not work. Thanks in advance for your time. ---------------------------------------------------------------------- egsuh · 2021-05-20 10:57 Once you define event handler in Frame and put it on a Form, then frame's events should and will fire, if you do nothing else. But you can assign the eventhandler from the form as well. This will override event-handling procedures defined within frame. Problem is, once you have defined event handler in the form, the form takes control over frame's event even though you remove the event- handler defined in the form --- so do nothing.  You can check this by opening form's .lfm file There will be inherited + component names on frame. To avoid this, there are a few options. 0.  Override all eventhandlers of frames in form again -- by just calling frame1.button1click(nil), etc.  1.  Delete the frame from the form, then re-insert frame. 2.  Do not put frame within form during design time. Create the frame within code. 3.  Open .lfm file of the form, search for "inherited" + control name of frame's controls, and remove event handler assignment there. Logically number 3 must be the easiest solution, but the form takes over control of frame's event handlers even though you click the eventhandler definiiton cell of object inspector inadvertently, and is not removed until you correct .lfm file. ---------------------------------------------------------------------- MarkMLl · 2021-05-20 12:21 Quote from: egsuh on May 20, 2021, 12:57:09 pmProblem is, once you have defined event handler in the form, the form takes control over frame's event even though you remove the event-handler defined in the form --- so do nothing.  You can check this by opening form's .lfm file There will be inherited + component names on frame. Note that this applies to most if not all properties, not just (pointers to) event handlers. MarkMLl ---------------------------------------------------------------------- Relativity · 2021-05-20 12:51 Thank you very much, egsuh and MarkMLI. I have tried option 1 suggested by egsuh and it perfectly works. Thanks also for the rest of the information. ---------------------------------------------------------------------- MarkMLl · 2021-05-21 07:08 Quote from: jamie on May 20, 2021, 11:29:03 pmThat's an old problem that I see still isn't fixed.. There should a version check feature in the OI when changes are made and offer the option to rebuild the LMF with the name changes.. I'm not sure that's relevant. What would be more useful would be a frame being read-only as far as the form's property editor was concerned. MarkMLl ---------------------------------------------------------------------- imekon · 2026-02-19 10:35 I'm seeing events disappearing from a TFrame in another form too. My solution was to remove and reinsert the frame, then it all works again. However, this has happened more than once. I'm not overriding the events in the parent form, this just feels brittle. ---------------------------------------------------------------------- egsuh · 2026-02-19 11:47 QuoteI'm seeing events disappearing from a TFrame in another form too. My solution was to remove and reinsert the frame, then it all works again. However, this has happened more than once. I'm not overriding the events in the parent form, this just feels brittle. Once you drop a frame on a form, and then any controls are clicked inadvertently, then the form's event handler is created and frame's event handling procedures are ignored. ---------------------------------------------------------------------- tetrastes · 2026-02-19 12:04 Generalizing, after placing (i.e. copying) a frame on a form in designer, the copy of frame and the original frame become independent of each other. ---------------------------------------------------------------------- Xenno · 2026-02-19 13:58 Personally, I prefer a TForm with bsNone and alClient. Insert it inside a Panel or other kind containers. TForm can be created by application or only when needed and has OnCreate/OnDestroy events. A little ceveat would be color synchronization. ---------------------------------------------------------------------- CharlyTango · 2026-02-24 14:53 Since the first versions of Delphi, frames have always caused problems when used in the GUI. And nothing has changed in that regard. They work wonderfully when created at runtime and, for example, a TPanel is used as a control element. Of course, you can also use a TForm if you absolutely need a create/destroy. However, these events can also be created in a TFrame. My rule is: Never use a TFrame in the GUI. ---------------------------------------------------------------------- Xenno · 2026-02-24 19:34 Totally agree. What you mean GUI is the Lazarus IDE, no? I guess the main advantage of a TFrame is we can see how it looks on design time by inserting it in a form so we can adjust if needed. We ought to set properties and event handling as much as we can in the frame unit; not on the inserted ones. We may need to do so when we insert the frame more than once which have differencies. Yes, it is easy get glitches with TFrame behaviours. That's why I prefer TForm if we aim for modularity although I could only see how it looks on runtime. ---------------------------------------------------------------------- n7800 · 2026-02-24 22:45 I have to agree that frame changes don't automatically update all open forms, and this often leads to problems. There have been many duplicate reports of such bugs (or feature requests, but whatever). But that's no reason to never use them. They work well as long as you don't edit in IDE both the frame and the form using it simultaneously. In theory, a frame is like a component. It's developed "once", and then simply connected to forms. ---------------------------------------------------------------------- Handoko · 2026-02-25 02:16 TFrame has many limitations, I had bad experience using it. I personally prefer using TForm in a TForm.