I was asked to chime in on a question on FaceBook…
Contents
The question
“What should I use for writing database centric desktop applications? FireDAC or TMS Aurelius”
Many good replies were made, and I attempted to make one too.
Unfortunately Facebook did not accept my quite lengthy reply, hence this blogpost which I assume can be of use for others aswell.
The reply
Jens Fudge Absolutely…. I’m always up for doing some promotion for kbmMW
First why not to use kbmMW (as we know it from the old days):
In this case it has been mentioned it is a database centric desktop application. Hence there are no direct mentioned requirement for a multitier solution, although I would argue that if there are going to be multiple desktop applications that will access the same database, I would recommend looking for a 3-tier solution with an application server in the middle, which is the original design goal for use of kbmMW.
However, now I will mention why to use kbmMW (as it is today):
1) The ORM:
You obviously have looked at how to abstract datastorage, since you have TMS Aurelius on your list of interesting tools.
kbmMW contains a very capable ORM (Object Relational Modelling) tool probably with many similarities to other tools in the sense that you can define (or get defined) a set of Delphi classes thru which you can operate your database.
Hence if you have a “person” table you would usually also have a Delphi class (a model) named TPerson which (depending on framework) match the database table in various ways.
kbmMW is able to make those models for you, and it can even keep track of minute changes in the models vs how the actual database table has been designed and make any change needed while keeping your data intact.
So if you need a field, you simply add it to your model. Lets say you need an Age field in your TPerson model, then you just add it potentially as a field or a combination of field and property as you would normally do in Delphi code:
property Age:integer read FAge write FAge;
Then tell kbmMW to update your database based on the model like this: ORM.CreateOrUpgradeTable(TPerson);
kbmMW will figure out everything by itself, and ensure you will have another field in the database.
When you want to look for a person instance, you will use ORM.Query<TPerson>(…..)
where the arguments to Query can be a the model fields to search on or a kbmMW SQL query statement if you want to do something more complex. eg:
SELECT Name,Age*2 FROM uMyModels.TPerson ORDER BY Age DESC
It supports joins, grouping, and much much more.
I chose to use an own SQL syntax because most people know SQL, and the attempts where you have to combine various Delphi statements to get the same result are usually much less readable.
What is important to understand, is that kbmMW does not just forward the statement as is to the database (unless you want it to). It compiles it itself, and applies the result on the database, using whatever syntax the database supports. Hence you only need to know one SQL syntax (kbmMW’s) and it will work against all databases supported by kbmMW’s ORM.
There are obviously many other details in this. There are loads of info about the ORM here:
2) SmartBinding
SmartBinding is designed from scratch for end user applications, doing something of the same as LiveBinding is doing, but in a completely different way, which means it is easy to refactor your applications without loosing your bindings. Further SmartBinding use one syntax for binding just about any type of model or control with any other type of model or control with a single syntax. No weird intermediate class instances are needed. Everything is handled by SmartBinding.
You can read more about SmartBinding here:
3) SmartEvents
Where SmartBind is the glue between data and presentation, SmartEvent is the glue between triggers and events. What happens when?
It is basically Delphi’s events on steroids, and made in such a way, that you can always refactor your application without your event setup being damaged, unlike Delphi events.
That also means you can easily load in and unload visual frames or forms and have them automatically get live data and bind the frame/form’s functional elements (like buttons etc) into the existing application framework without having to you manually needing to rebind your events.
You can read more about SmartEvent here:
and you can see a presentation about both SmartBinding and SmartEvent here:
4) Configuration
Your application usually will need some sort of configuration. The simplest way is reading stuff from an INI file or the registry. But what if you could make configuration handling easier? kbmMW also bundels that feature which you can read about here:
The blog mentions REST, but the configuration framework is generic and can be used for anything.
5) Logging
You will also want some sort of smart logging mechanism. Again kbmMW contains a very advanced one you can use:
Again this article mentions REST but it is completely generic and can be used everywhere you need it.
6) Scheduler
Your application most likely needs some sort of timer based stuff… “Do something at specific times” kind of thing. kbmMW comes with the most complete Scheduler for Delphi which you can read about here:
7) Date/Time
Most applications talking directly or indirectly with a database, needs good date/time handling. Delphi has TDateTime, but it is really just a floating point value, which has no knowledge about which time zone the time is in.
That results in many developers really not coding for multiple time zones. They expect their application and data will only be used locally within one time zone, but the truth of all is that applications work globally and interaction between data from different places on the globe is increasingly happening. Hence TDateTime is seriously outdated.
kbmMW comes with TkbmMWDateTime which is a TDateTime on steroids and supports all sorts of formats and date/time parsing and conversion. Read more about it here:
8) LINQ
It is more a nice to have than need to have feature, but it does make some things much easier.
Basically kbmMW’s LINQ allow you to do various operations on an object or a list of objects, datasets, stringlists, XML/JSON/YAML etc. like calculating sum, filtering, grouping and splitting, ordering and much more in a very simple way.
Read more about it here:
9) XML, JSON, BSON, MessagePack, YAML?
You may have requirements to manipulate all of these types of data, and you may need to be able to convert seemlessly between them. kbmMW comes with all the tools for that, based on the kbmMW object notation framework. Read more here:
kbmMW even supports analysing your data and produce Delphi classes that can be used for reading, writing the data and convert it to any of kbmMW’s supported formats.
10) Memory debugging/leak tracing/stack info.
All also available in kbmMW.
Read here:
11) Security, safe passwords, state of the art encryption, random numbers and hashing methods
kbmMW contains it all, inclusive:
I could go on and on, because kbmMW is simply such a vast toolbox for anything Delphi central framework for all things development. You will not find a framework anywhere with the amount of quality features that kbmMW provides out of the box.
So you should choose the method that you feel comfortable with.
If you want the most complete framework, there really are no alternatives to kbmMW.
If you want the most complete framework, there really are no alternatives to kbmMW.
I have been using kbmMW in desktop applications for 10 years, I am a fan. It’s a good framework. It works cool. But it is also a big pain:
1. The weak documentation. I can’t understand some approaches or methods.
2. The absence of demos with fresh features
3. The hidden errors in my complex application after any new release of kbMW (The last two was a broken JSON and a problem with load table from XML)
4. The ORM is cool – but I spent a lot of time on adaptation it with Firebird Database on my MPV project. I didn’t resolve a problem with creating definitions for hierarchical classes. I don’t sure what I will use ORM on my real application.
5. The absence of support. The waiting three or four weeks for an answer on errors’ notice – It is unacceptable
Hi Kim,
I uses 2.61 long time and 5.xx, so flexible product,
in my opinion you need to open a demo page on github
For the product, it would be much better if there was script language support.
I am currently trying to do something with python language.
a flexible infrastructure by using the power of kbmmw within the scripting language.
Best Regards
I use FastScript as a scripts interpreter in my projects. it’s very powerful
Hello Vadim,
I am interested in this topic, can you post sample code snippet
best regards
dryphon@gmail.com
This is a simple example. You can use the script from a file on kbmMW server. It can be used for changing the servers logic without changing a servers code.
unit Unit24;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, fs_iinterpreter, fs_iclassesrtti, fs_igraphicsrtti, fs_iformsrtti, fs_iextctrlsrtti, fs_idialogsrtti, fs_iinirtti, fs_imenusrtti,
fs_ipascal, fs_icpp, fs_ijs, fs_ibasic, fs_tree, Vcl.StdCtrls;
const script = ‘var s2 : String;’ +
‘begin ‘ +
‘s2 := ”Test”; ‘ +
‘s2 := sInput + s2;’ +
‘ShowMessage(”ShowMessage from Script ” + s2);’ +
‘sOutput := s2;’ +
‘end. ‘;
type
TForm24 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form24: TForm24;
implementation
{$R *.dfm}
procedure TForm24.Button1Click(Sender: TObject);
var s : TfsScript;
begin
s := TfsScript.Create(Self);
s.SyntaxType := ‘PascalScript’;
s.Parent := fsGlobalUnit;
s.Lines.Add(script);
s.AddVariable(‘sInput’,’String’,’DataForScript’);
s.AddVariable(‘sOutPut’,’String’,’DataForScript’);
// s.Compile;
s.Run;
ShowMessage(‘sOutPut: ‘ + s.Variables[‘sOutPut’]);
s.Free;
end;
end.
Hi,
C4D actually did have a product, that included script support, kbmMWM (kbmMW Management framework). It was back in the 2.5-3.x timeframe as I remember.
Despite the countless hours put into making an easy to use management console etc. for handling myriads of kbmMW servers, including (3rdparty) scripting built in, it was never a hit between users.
So I discontinued it after some years.
However I do understand the feature of scripting in relation to kbmMW could be very useful to some. I am however a bit unsure about exactly what level of scripting is really asked for.
Is it interesting to have a complete scripting based development IDE/kbmMW system and why? I somehow find it questionable that people would want to write a complete kbmMW based n-tier system in script language, when they can use Delphi and for some versions of kbmMW Lazarus/FPC for the same?
Hence my take would be to use scripting for specific functionality, like custom calculations and string management etc.
For that purpose kbmMemtable’s SQL parser actually works wonders as it can handle non SQL expressions to which can include math and string manipulation with variables, native functions etc.
In fact right now I am working on extending that feature to include scripted functions written in a math type of way: myfunc1(x,y)=sin(x)*y etc.
It even supports conditions and loops to make for a relatively simple to use, but very powerful scripting engine (that I am using in various customer projects too).
Then there is the scripting which produce for example HTML or other types of output. Is that a need/wish?
/Kim
Hi,
I’ve been writing desktop applications for years and I want to replace that with the web.
I want to create my business objects on the server layer using scripts and output html in the user interface.
I’ve been doing a qaurtex pascal review lately. kbmmw and qaurtex can be a good couple. I’ll do R&D on it.
Exactly what I mean is an integrated development environment, like sap.
best regards