<div dir="ltr">Hey all,<div><br></div><div>I was experimenting with using some of FPC's features together and came up with this:<div><br></div><div><a href="https://github.com/tangentstorm/lazmvc/blob/master/umodel.pas">https://github.com/tangentstorm/lazmvc/blob/master/umodel.pas</a><br>
</div><div><br></div><div style>Basically, it's just a generic implementation of the Observer design pattern. It provides a class, TModel, tha you can use as an interface delegate to make any TObject into a subject. (You can also just subclass it.)</div>
<div style><br></div><div style>It also provides GModel<t>, a genericized version of TModel that contains a property, value : T, which notifies observers when that value is is changed.</div><div style><br></div><div style>
The notification is done through message methods, which means that any TObject can act as an observer and receive callbacks.</div><div style><br></div><div style>The rest of that repository is a Lazarus project that demonstrates how to use observers to implement the model-view-controller pattern.</div>
<div style><br></div><div style>The main form provides the view, which is just a little progress bar turned on its side to act like a volume meter. </div><div style><br></div><div style>Clicking the "settings" button opens the Controller, which in this case is just a separate form that has a slider control.</div>
<div style><br></div><div style>Because the main form registers itself as an Observer of the model that the controller is managing, moving the slider on the controller causes the main form's View to update in real time.</div>
<div style><br></div><div style>Anyway, it was kind of fun to make and demonstrates some of the more interesting features of ObjFPC, so I thought I'd share. :)</div><div style><br></div><div style>You can clone the project through git, or download the whole thing as a zip file from here:</div>
<div style><br></div><div style><a href="https://github.com/tangentstorm/lazmvc/">https://github.com/tangentstorm/lazmvc/</a><br></div><div style><br></div><div style>-michal</div><div style>(aka tangentstorm on #fpc)</div>
<div style><br></div></div></div>