Recent

Author Topic: How to mark a collection property as modified after some items changed  (Read 2139 times)

alpine

  • Hero Member
  • *****
  • Posts: 1302
I have a component with ControlStyle + [csDesignInteractive] and when an item changed via mouse input (into the Designer), I would like the whole component to be marked as such. 

I have no idea how to do it, advice please.

EDIT: To be more specific: the component is a map viewer and when a point, which belongs to a track, was dragged with a mouse, then the designer must be notified for the change. That is not the usual way to change a property (e.g. via TPropertyEditor) so it is the notify method
« Last Edit: July 08, 2024, 12:18:30 am by alpine »
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

Thaddy

  • Hero Member
  • *****
  • Posts: 16192
  • Censorship about opinions does not belong here.
Components, both design time and runtime derive from Tpersistent and that implements IFPObserver and IFPObserved.a.k.a. observer pattern. That can be used in your situation.
For example a TCollection or a TStringlist implement it as standard.

Michael wrote a very good article on objervers and mediaters

https://www.freepascal.org/~michael/articles/cdcover/cdcover.pdf
the sources are here:
https://www.freepascal.org/~michael/articles/cdcover/cdcover.zip

The unit from that project you are most interested in is the unit lclmediators.
« Last Edit: July 08, 2024, 08:17:01 am by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

alpine

  • Hero Member
  • *****
  • Posts: 1302
Thank you for the reply!

I'm aware of the observer pattern and the Michael's article, but my problem is actually how to inform the IDE for the property change. 

On the 1-st attached picture, when you change the Latitude property, the save button (blue diskette) lit immediately, which means the TFloatPropertyEditor made his job to propagate the change up to the designer top level.

On the 2-nd picture, when you drag a point interactively, the save button stays gray, the Latitude isn't modified by means of TPropertyEditor and there must be a way to inform the designer that a property was changed. At that point I'm lacking the knowledge how to do it. Documentation on the matter is scarce or I just couldn't find it.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

wp

  • Hero Member
  • *****
  • Posts: 12464
Not sure, but it seems to me that you must override the collection property editor for the trackpoints to get access to the Modified method. Try to study the code in ideintf/propedits - hard stuff, I know...

alpine

  • Hero Member
  • *****
  • Posts: 1302
Not sure, but it seems to me that you must override the collection property editor for the trackpoints to get access to the Modified method. Try to study the code in ideintf/propedits - hard stuff, I know...
After lot of trials and errors with LazIDEIntf/PropEdits/ComponentEditors, etc., finally I have "assembled" kind of MapView point editor for the IDE. Not sure that it will be very convenient nor useful but at least it's runtime part (TMapEditMark, TMapEditorList) will do. The commit is r9385.

I'll be happy on any feedback.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

vfclists

  • Hero Member
  • *****
  • Posts: 1146
    • HowTos Considered Harmful?
Re: How to mark a collection property as modified after some items changed
« Reply #5 on: October 18, 2024, 08:04:01 pm »
Not sure, but it seems to me that you must override the collection property editor for the trackpoints to get access to the Modified method. Try to study the code in ideintf/propedits - hard stuff, I know...

That code needs better documentation and a diagram displaying its principles and how it all hangs together.

I had a hard time trying to make sense of it and get it to work in my project, only to have a two-line change fix my problem.
Lazarus 3.0/FPC 3.2.2

 

TinyPortal © 2005-2018