Recent

Author Topic: onFormChanged event  (Read 2427 times)

warleyalex

  • New Member
  • *
  • Posts: 24
onFormChanged event
« on: August 13, 2018, 12:18:34 am »
The plan would be to implement an IDE notifier to the Lazarus plugin IDE project event onFormChanged.

For instance, whenever a form designer has been changed I would like to fire a method. e.g. You drag 'n drop a TLabel widget into designer, set the Caption to 'abcd' and then fire the event "onFormChanged".

So, I am stuck on this plan.

Any idea is very welcome.
« Last Edit: August 13, 2018, 04:48:06 pm by warleyalex »

warleyalex

  • New Member
  • *
  • Posts: 24
Re: onFormChanged event
« Reply #1 on: August 13, 2018, 04:53:41 pm »
Every designed LCL form has a Designer of type TIDesigner. The IDE creates designers of type TComponentEditorDesigner defined in the IDEIntf unit componenteditors.

You get notified when a designer form is modified with this piece of code:

Code: Pascal  [Select]
  1. GlobalDesignHook.AddHandlerModified(@Extension.OnDesignerModified);
  2.  

...but there is an issue here:
the designer is notified using only the Object Inspector!
 
Important note:
when you resize a component at design-time, you resize with the mouse, dragging the component, the designer is not notified!

Any idea?

warleyalex

  • New Member
  • *
  • Posts: 24
Re: onFormChanged event
« Reply #2 on: August 13, 2018, 07:13:52 pm »
I'll share you guys the solution.

...the problem of the method AddHandlerModified is triggered after little change, for instance, if I set the WebLabel caption to 'abc' the method is fired 3 times. This is unwanted. I only want to trigger on form save.

Code: Pascal  [Select]
  1. GlobalDesignHook.AddHandlerModified(@Extension.OnDesignerModified);
  2.  

I found the undocumented method AddHandlerOnSaveEditorFile. We can fire the method LFM-TO-PAS "on before save" the form unit.

Code: Pascal  [Select]
  1. LazarusIDE.AddHandlerOnSaveEditorFile(@Extension.BeforeSaveCallLFM2PAS);
  2.  

Do not forget to use RemoveHandlerOnSaveEditorFile on the add-on the destructor.

This is the trick!
« Last Edit: August 13, 2018, 07:17:19 pm by warleyalex »