Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A very simple demo application demonstrating the general principle:</p> <pre><code>TModel = class property ValueList : TList &lt;Double&gt; read ... write ...; end; </code></pre> <p>You could then have multiple views that visualize the model, i.e. one view that displays the values in a table and one that displays the values in a diagram:</p> <pre><code>IView = interface ['{0D57624C-CDDE-458B-A36C-436AE465B477}'] public procedure Update; end; TTableView = class (TInterfacedObject, IView) private FModel : TModel; FController : TController; public procedure Update; end; TDiagramView = class (TInterfacedObject, IView) private FModel : TModel; FController : TController; public procedure Update; end; </code></pre> <p>The views do only read data from the model. All interaction with the GUI is delegated to the controller class (which uses the Observer design pattern by the way):</p> <pre><code>TController = class private FModel : TModel; FViewList : TList &lt;IView&gt;; private procedure UpdateViews; public procedure AddDataValue (Value : Double); end; </code></pre> <p>The implementation of AddDataValue could look something like:</p> <pre><code>procedure TController.AddDataValue (Value : Double); begin FModel.ValueList.Add (Value); UpdateViews; end; procedure TController.UpdateViews; var View : IView; begin for View in FViewList do View.Update; end; </code></pre> <p>This way you achieve multiple things:</p> <ul> <li>You can easily use multiple views (either allow the user to switch beetween views, or show them simultaneously)</li> <li>All data is in the model and completely separated from the presentation. Change the representation, change nothing in the model.</li> <li>To implement persistance you only have to save the model.</li> <li>You could use the controller to execute all necessary checks. (Instead of implementing this for each view)</li> </ul> <p>For a complete list of advantages, the web is full of discussion of the MVC pattern and its alternatives.</p> <p>In Delphi applications you may find that the controller is kind of overhead because of the event-based programming style in Delphi. What I often do is to only split my application into model and view.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload