Recent

Author Topic: TFrame in a TForm, events disappear..  (Read 9437 times)

julgus

  • New Member
  • *
  • Posts: 29
TFrame in a TForm, events disappear..
« on: October 14, 2016, 11:59:13 am »
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...
« Last Edit: October 14, 2016, 01:07:21 pm by julgus »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: TFrame in a TForm, events disappear..
« Reply #1 on: October 14, 2016, 01:07:49 pm »
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

  • New Member
  • *
  • Posts: 29
Re: TFrame in a TForm, events disappear..
« Reply #2 on: October 14, 2016, 01:25:30 pm »
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

  • Hero Member
  • *****
  • Posts: 4144
Re: TFrame in a TForm, events disappear..
« Reply #3 on: October 14, 2016, 05:03:12 pm »
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

  • Full Member
  • ***
  • Posts: 103
Re: TFrame in a TForm, events disappear..
« Reply #4 on: May 20, 2021, 11:09:51 am »
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.
"How'm I gonna get through?"
  -- Pet Shop Boys

egsuh

  • Hero Member
  • *****
  • Posts: 1289
Re: TFrame in a TForm, events disappear..
« Reply #5 on: May 20, 2021, 12:57:09 pm »
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

  • Hero Member
  • *****
  • Posts: 6683
Re: TFrame in a TForm, events disappear..
« Reply #6 on: May 20, 2021, 02:21:56 pm »
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.

Note that this applies to most if not all properties, not just (pointers to) event handlers.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Relativity

  • Full Member
  • ***
  • Posts: 103
Re: TFrame in a TForm, events disappear..
« Reply #7 on: May 20, 2021, 02:51:13 pm »
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.
"How'm I gonna get through?"
  -- Pet Shop Boys

MarkMLl

  • Hero Member
  • *****
  • Posts: 6683
Re: TFrame in a TForm, events disappear..
« Reply #8 on: May 21, 2021, 09:08:06 am »
That'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
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018