DelphiMVCFramework 3.4.1-sodium

👉 DelphiMVCFramework 3.4.1-sodium is out!

This isn’t a feature realease, but contains fixes and some small improvements that can improve your day by day job with the framework.

The latest DelphiMVCFramework version is always available at this link.

DelphiMVCFramework Book

While all these new features can change and simplify the way you’ll write your next APIs, the contents in the Official Guide is still largely relevant and all the concepts explained there are still valid. To avoid to reinvent-the-weel, and to follow industry best practices, I suggest to all the serious DMVCFramework users to read DelphiMVCFramework: the official guide book that will cover from the basic utilization to the advanced scenarios with a lot real-world samples and how to sections. More info about the book and its translations here.

Supporting DMVCFramework with PATREON

By becoming a PATREON supporter, you will gain access not only to this invaluable video series but also to an extensive repository of exclusive content. This includes advanced programming tutorials, expert insights, and practical tips, all designed to enhance your programming expertise.

DMVCFramework PATREON community is getting bigger and bigger at each month. Joining the DMVCFramework PATREON community provides more than just educational content; it is an opportunity to connect with a network of passionate developers. Here, we embrace the principle of ‘Scientia potentia est’ (Knowledge is power), striving for continuous learning and improvement in our craft.

What’s new in DelphiMVCFramework-3.4.1-sodium

  • âš¡ Improved support for .env (dotEnv) configuration files. Now it is possibile to run a dmvcframework console server with a command line like the following:

    set dmvc.server.port = 9999 && MyCoolService.exe
    

    All the other .env based configurations can be used in this way. It is very useful in case you need to run many instance of the same service binding on different TCP/IP ports or if you want to temporary enable the built-in profiler or if you want to change one of the other configuration values “just for this run”.

  • âš¡ Improved method GetRenderedView. Now it gets an optional JSONObject directly usable by the template (in case of Server Side Rendering). The method signature is:

    TMVCController.GetRenderedView(
        const AViewNames: TArray<string>; 
        const JSONModel: TJSONObject): string;
    

    This method can be used as shown below:

    function TWebSiteController.ShowModalForDelete(guid: string): String;
    begin
      var lJSON := TJsonObject.Create;
      try
        lJSON.S['title'] := 'Bootstrap Modal Dialog';
        lJSON.S['message'] := 'Do you really want to delete row?';
        lJSON.S['guid'] := guid;
        Result := GetRenderedView(['modal'], lJSON); 
        //Note - lJSON is not owned by GetRenderedView, must be freed manually.
      finally
        lJSON.Free;
      end;
    end;
    
  • âš¡ Improved HTML exception rendering, IMHO the previous one too much colorful. Now the unhanled exceptions are rendered using the following color/font schema.

  • âš¡ Improved support for legacy schemas which use 1/0 values instead of true/false values. MVCActiveRecord - in case of “integer field types” specified in the MVCTableField attribute DataFieldName, if the entity property is a boolean value, 1 and 0 are mapped as true and false. This feature is expecially useful for all of those database designed before boolean type was available for FirebirdSQL. Now you can use a proper true/false value in your objects and automatically maps those values as 1/0 integer value.

  • âš¡ New sample to show how to use Microsoft ADO in a DMVCFramework service (https://github.com/danieleteti/delphimvcframework/tree/master/samples/ado)

  • âš¡ New Wizard option to enable Profiler directly from a configuration value. For new project generated by the new wizard you can enable the built-in profiler just defining dmvc.profiler.enabled=true in a .env file. For older projects, you can just add the following code just before the RunServer call.

      if dotEnv.Env('dmvc.profiler.enabled', false) then
      begin
        Profiler.ProfileLogger := Log;
        Profiler.WarningThreshold := dotEnv.Env('dmvc.profiler.warning_threshold', 2000);
      end;
    

    Using the new support for .env vars passed from the command line, you can enable the profiler for an already built service lauching it with the following command line:

    set dmvc.profiler.enabled = true && MyCoolProject.exe
    
  • âš¡ New Mustache helpers to default Renderer. In DMVCFramework-3.4.1-sodium has been added a virtual method to allow applications writer to subclass the Mustache Renderer to add additional features such as new Mustache lambdas (callbacks) and Translation callbacks (check the mustache sample). Moreover, dmvcframework adds “standard” helpers and the developer can add project specific helpers.

  • âš¡ New MVCFromContentFieldAttribute, which works like MVCFromQueryStringAttribute but it is usable with url-encoded form data. Very useful with HTMX and, in general, with server side technologies.

  • âš¡ Improved All the methods specific to HTMX (available after including MVCFramework.HTMX.pas) are now prefixed with HX to make it more clear that are dedicated to HTMX support.

  • âš¡ New Deserialiser named TMVCURLEncodedSerializer for URLEncoded Body (from an idea by David Moorhouse). URLEncoded Serializer is able to deserialize data as JSONObject too. Check the sample serversideviews_mustache

  • âš¡ New methods Page, PageFragment, SetPagesCommonHeaders and SetPagesCommonFooters. Removed the old LoadViewFragment method. These 4 methods make even more simple to work with server side view. Here’s an example.

    procedure TWebSiteController.OnBeforeAction(AContext: TWebContext;
      const AActionName: string; var AHandled: Boolean);
    begin
      inherited;
      //all the views generated by this controller with the method "Page" will use
      //'header' as the first view fragment and 'footer' as the last view fragment. 
      SetPagesCommonHeaders(['header']);
      SetPagesCommonFooters(['footer']);
    end;
    
    function TWebSiteController.PeopleList: String;
    var
      LDAL: IPeopleDAL;
      lPeople: TPeople;
    begin
      LDAL := TServicesFactory.GetPeopleDAL;
      lPeople := LDAL.GetPeople;
      try
        ViewData['people'] := lPeople;
        Result := Page(['people_list_search', 'people_list', 'people_list_bottom']);
    
        // Page method consider the common headers and footers, 
        // so the views actually rendered are:
        //    header, people_list_search, people_list, people_list_bottom, footer
    
        //  PageFragment is the same but doesn't consider the 
        //  common headers and footers. It is useful when you 
        //  need to generate a "fragment" of a page instead of a complete page.
      finally
        lPeople.Free;
      end;
    
    end;  
    
  • âš¡ New ViewData[] is now a TValue dictionary instead of a TObject dictionary.

  • âš¡ New TMVCActiveRecord.TryGetSQLQuery<T> and TMVCActiveRecord.TryGetRQLQuery<T> to test if a named SQL (or RQL) query is available. It is very useful to test if a NamedQuery is available to call. Check sample activerecord_showcase.

  • âš¡ Improved Lua View Engine for Server Side Views.

  • âš¡ Added IMVCDotEnv.RequireKeys(const Keys: TArray<String>) very useful to test if required configuration keys are available, just at the start of the program. If a particular configuration value is required but not set, it’s appropriate to raise an error. To require configuration keys:

      dotEnv.RequireKeys(['SERVICE_APP_ID', 'SERVICE_KEY', 'SERVICE_SECRET'])
    

    If any of the configuration keys above are not set, your application will raise an exception during initialization. This method is preferred because it prevents late runtime errors in a production application due to improper configuration.

  • âš¡ Updated LoggerPro to version 2

  • âš¡ New “Use MSHeap” on Wizard (Thanks to Roberto Della Pasqua for the MSHeap wrapper)

  • âš¡ New Object versioning for TMVCActiveRecord using new option foVersion. Check sample activerecord_showcase.

  • âš¡ New TMVCActiveRecord.TableName is now readonly

  • âš¡ New In the contrib folder (so not in the main source folder), there is the new ViewAdapter for the Sempare Template Engine for Server Side Views. More on this directly from the author Conrad Vermeulen. The Sempare Template Engine has a dual license, if you want to use it for commercial developments be sure to adhere to the license. Check the sample serversideviews_sempare.

  • âš¡ Added TMVCActiveRecord.GetCustomTableName which allows to overwrite the tablename defined in the MVCTableName attribute. Just overwrite the method in descendant classes and return the tablename to use for the current instance.

  • âš¡ Added support for table name and field name with spaces for MySQL and MariaDB in TMVCActiveRecord.

Enjoy!

– Daniele Teti

Comments

comments powered by Disqus