Archive for the ‘Delphi’ Category

Linux Compiler will remain an Enterprise Only Feature

Friday, August 9th, 2019

In case you have not been watching RSP-17195 Marco just closed the ticket yesterday. Apparently EMBT has decided that the Linux compiler will remain an Enterprise edition feature and will not appear in the Pro edition as requested.

I have written before as to why I think this a major marketing mistake, so just briefly, Linux is used by more hobbyist programmers and IoT/SBC developers than most other OSes, and there are many FOSS solutions available. Few people interested in targeting Linux will pay for the Enterprise Edition as they can target a Windows machine and pay the M$ license cheaper than buying an Enterprise edition. It also makes no sense to allow the targeting of Windows and MacOS in the Pro edition, but not the other desktop target. I think this is the same mistake that was made when originally selling the Mobile AddOn, which EMBT later decided to include in Pro in order to limit development costs and increase the user base. Licensing FMXLinux will likely not amount to much of an incentive as my understanding is most developers who have currently licensed the Enterprise edition are writing server apps. Increasing the cost of writing a desktop app will not encourage the uptake of hobbyist or professional developers looking to monetize apps on a platform that users typically prefer FOSS solutions.

Other vendors like REMObjects do not charge additional money for a product edition to target a supported platform. You get all platforms for the same subscription price, and they have now written an RTL and WASM support which makes their platform that much more attractive to Delphi developers. REMObjects also has 64 bit ARM target support today.

.NET cannot be ignored now that .NET Native and Core have been released and are rapidly maturing. Delphi’s “native” compilation is no longer an advantage and the C# code generated tends to be more efficient than Delphi’s various compilers by all accounts.

You can have the greatest product in the world, but if you cannot sell it to a sufficiently large user base, it will not be self sustaining. Marketing decisions like this IMHO will negatively impact the Delphi user base.

Delphi Now Has Linux UI Support

Wednesday, June 26th, 2019

Just announced, FMXLinux has been licensed from KSDev for inclusion in the Enterprise and Architect editions of RAD Studio and related products (Delphi & C++ Builder).  The product is available via GetIt for all current subscribers.

Since I have been following FMXLinux’s development for some time, I immediately installed the licensed version.  Unfortunately, the IDE experience is the same as the trial I previously installed directly from KSDev.

I created a new Multi-device application with tabbed navigation from the wizard.  Looking at the list of target platforms (Android, Mac OS, iOS, Windows) I didn’t see Linux.  Fair enough, the templates on which the application is based do not contain the new UI platform.  Perhaps in a subsequent release since as per Marco’s introduction the product has not been fully integrated into the IDE.

I went to add the new platform to the solution, by Rt. clicking The Target Platforms node in the project manager and it is greyed out.  If I delete a target it is re-enabled, but the list of targets I can add only contains the one I just deleted.  Rt. Clicking on the Application node in Projects window, there is an option “Add Linux Platform”.  Now I get a Linux 64 bit target platform node.

This is covered in Marco’s introduction, but he doesn’t mention that attempting to add a component to my UI doesn’t work.  I can’t add a button to my form until I switch to another target platform, and then switch back so I can actually deploy and test on Linux.  This has been a known issue with the trial, and I was hopeful that such a poor user experience would be fixed now that EMBT has licensed the product.  For now, it’s an issue you will have to work around, and I’m sure it will be corrected in a future release.

While only major Linux distros are currently supported (Ubuntu, RedHat and possibly a couple others) the team at KSDEV are working to support others including the more obscure ones like Elementary OS.  I for one am very pleased that Delphi finally can target Linux with GUI applications making it a complete XPlatform desktop solution for all 3 major targets.

Android - The case of the vanishing file

Saturday, June 22nd, 2019

I’m relatively new to the Android development platform, coming from the Windows desktop. One of the great things about recent editions of Delphi is it’s ability target numerous other platforms. One of the worst things about recent versions of Delphi is it’s ability to target platforms you are not as familiar with. If your use case is atypical, you can quickly find yourself swimming in shark infested waters. You never know what is going to byte you, a bug in the platform, a bug in Delphi RTL or FMX code, a bug in your code, or just your lack of knowledge about the platform.

Today I was trying to figure out why files I was saving to the Documents folder on my Android LG5 were visible from the Android File Manager, but not present when I connected the phone to a Windows, or Ubuntu desktop. Turns out there is a long outstanding bug in Android that google has not even acknowledged. In order to see new files when connecting to a device using the MTP protocol, you may need to re-boot the Android device before the files appear. Indeed once I did so, my files appeared and I could copy them off to my PC. You may want to comment on this motion to get the issue re-opened and addressed.

Hopefully this helps someone else avoid spending a lot of time scratching their head…

JIRA is Down

Thursday, May 16th, 2019

Just a note to EMBT customers, JIRA has been down for several hours now.  It is currently giving the following message

HTTP Status 500 - org.ofbiz.core.util.GeneralRuntimeException: Could not determine database type. (Network error IOException: Connection refused: connect)

With a Java callstack if you like that kind of thing.  EMBT has been advised and I’ve been told EDN may also be affected. Hopefully it will be back up shortly.

More Persistence with Spring4D ORM

Wednesday, May 15th, 2019

Today I decided to ensure the project I am working on is in fact database independent. The best way I have found is to make sure you develop and test on multiple databases as you go. Since the ORM portion of Spring4D often called Marshmellow is supposed to isolate your application from the underlying data store, I figured it would be a piece of cake.

The Spring4D ORM supplies numerous database adapters including UIB (Unified Interbase). There is also another I found for IBX. I decided to try UIB since I want minimal deployment dependencies and am using Firebird, but was a little concerned since the last commit was from Jun 13, 2016.

After pulling down the source code from the repo I discovered that there are no projects for Delphi Rio, so I copied the projects for the last version (21) and renamed them to create Rio projects. Getting the components installed proved quite easy, but once I had the basic data ORM setup code for an alternate database incorporated into my project, that’s when the fun started.

Initially UIB would not load the GDS32.DLL from c:\Windows\System32 that was generated from my Firebird 3.0 Win64 install. Providing the full path did not resolve the issue, and GetLastError() wasn’t helpful so I changed the client library to fbclient, and the app crashed a little further down the line.

The ORM uses a TDatabaseManager class to build the database structures from the registered entity metadata when you call the BuildDatabase method.  It worked for SQLLite, but did not for Firebird as the database file did not exist. Unfortunately the TDatabaseManager was never designed to be extended. The class contains only private fields with no protected accessors, and the constructor as well as the BuildDatabase method, are not virtual. As a result I wrote the following decorator class to provide the extended functionality:

  TUIBDatabaseManager = class(TObject)
    FConnection :IDBConnection;
    FUIBConnectionAdapter :TUIBConnectionAdapter;
    FDatabaseManager :TDatabaseManager;
    procedure CreateTheDatabase;
    constructor Create(const connection: IDBConnection);
    procedure BuildDatabase;


  Spring.Persistence.SQL.Interfaces, {for TQueryLanguage}

procedure TUIBDatabaseManager.BuildDatabase;
  //if the database does not exist then create it
  if not FileExists(FUIBConnectionAdapter.Connection.DatabaseName) then


constructor TUIBDatabaseManager.Create(const connection: IDBConnection);
  FConnection := connection;
  FConnection.QueryLanguage := qlFirebird;
  FDatabaseManager := TDatabaseManager.Create(FConnection);
  FUIBConnectionAdapter := connection as TUIBConnectionAdapter;

procedure TUIBDatabaseManager.CreateTheDatabase;

After I got the database created, the application bombed because it was attempting to create boolean object fields as BIT database columns. Tracing through the code I found the where the datatype mapping was performed and added a snippet for FireBird 3 support after descovering that UIB already supported the Boolean datatype for Interbase and Firebird. All I had to do was compile UIB with the FB30 directive. Here is the amended version of the GetSQLDataTypeName method:

function TFirebirdSQLGenerator.GetSQLDataTypeName(
  const field: TSQLCreateField): string;
  Result := inherited GetSQLDataTypeName(field);
  {add support for Firebird 3.0/Interbase 7 new boolean datatype}
  {$ifdef FB30}
  if (field.TypeInfo.Kind = tkEnumeration) and
     (field.typeInfo = System.TypeInfo(Boolean)) then
    Result := 'BOOLEAN'
  if StartsText('NCHAR', Result) then
    Result := Copy(Result, 2, Length(Result)) + ' CHARACTER SET UNICODE_FSS'
  else if StartsText('NVARCHAR', Result) then
    Result := Copy(Result, 2, Length(Result)) + ' CHARACTER SET UNICODE_FSS';

Once I got that issue resolved the app crashed on a SQL snippet I had in a call to the ExecuteSQL method because Firebird likes quoted identifiers when you use mixed case column names. Once I had worked around that I found that Firebird threw many more errors importing data due to my Column attributes than SQLLite had. It also complained because I had used a reserved word in Firebird as a table name. After a some more fixups I had a running application capable of using either database back end. In the process I re-discovered how much I like Firebird, even if some of it’s SQL error messages are rather cryptic. It is also much faster importing data that SQLLite.

Persistence with Spring4D

Tuesday, May 14th, 2019

My blog tagline is certainly no accident.  I have been interested in persistence frameworks for a long time, and thought I would use Spring4D’s Marshmellow ORM for a project.  Spring4D has been around for quite some time and just had it’s first conference in Italy so I figured the framework was mature and warranted a closer look.  I had previously used the Spring4D DI container, and decided this time to use Spring4D collections as well to avoid as much code bloat as possible.

The first thing I discovered is that the Spring persistence layer aka Marshmellow has a very unfortunate name.  Trying to google it with “delphi” leads to all sorts of hits related that Android version.  The next thing I learned is that development has been put on hold as of September 2018 due to a lack of resources.  This is unfortunate, as there are not that many open source ORMs that use the newer language features of Delphi when compared C# or Java.

The third thing I quickly learned is that other than the Tests, there is not a whole lot of documentation available.  There is the reference help which is really not that helpful.  It doesn’t contain descriptions of the class interactions or architecture and has no examples of usage.  Really it’s not much more informative than drilling through the code.  The best source of “getting started” help that I could find is the previous bitbucket repo. There is of course also the google groups if you need to get clarification of something, and reading previous posts can help you from running into common issues.

As a newbie, it’s not clear how the [InheritenceAttribute()] works so I will have to investigate it further. I assume if the last descendant in a class hierarchy is the only one marked as an entity, it will by default have all the fields marked with the Column() attribute in all ancestor classes.

Another thing that is not particularly clear from any documentation is how the underlying datatype employed by the database is determined.  There are really only 3 pertinent parameters supplied to the Column() attribute, namely length, precision and scale.  Length only applies to string types and precision, scale to numeric.  It is unclear how precision and scale effectively change the numeric datatype and it’s corresponding precision or scale, other than for Integer datatypes you specify 0,0 for precision,scale.

I’m sure all this will become clear as I use the framework more, but some more thorough ‘Getting Started’ documentation would have been really nice.

How to get Login Dialogs Appearing on the TaskBar

Thursday, May 9th, 2019

Most of the applications I have worked on in Delphi are database apps that may present a splash form quickly followed by a login dialog.  If the user fails to authenticate, the application needs to terminate gracefully.  The only way to do so cleanly is to modify the DPR code with some conditional logic. I’ve seen scenarios where after the main form was created the login dialog was invoked and if authentication failed everything was torn down. This complicates the shutdown logic, and often didn’t work well, encouraging a call to Halt() and sometimes leaving the process in memory.

Any long time Delphi user knows that messing with the generated DPR code in Delphi can cause all sorts of grief later when Delphi tries to auto create forms and add units to the uses clause.  That is out of scope for this post, suffice to say that it is possible to write something like this:

  User :TUser;
  Screen.Cursor := crAppStart;
    Application.MainFormOnTaskbar := True;
    Application.Title := 'My Secure App';
    Application.CreateForm(TMainDm, MainDm);
    Screen.Cursor := crDefault;
  User := TfrmLogin.Login
    function (const UserName,Password :string) :TObject
      Result := MainDm.Session.FindWhere<TUser>(
      UserName can be passed as first parameter so don't
      have to type it in all the time
    3  {credential retries available }
  ) as TUser;
  if User <> nil then
    Application.CreateForm(TfrmMain, frmMain);
    frmMain.CurrentUser := User;

The problem is that the Login Dialog does not appear on the Windows Taskbar. If it is hidden behind other windows, the user may think the application has not been launched and attempt to start another instance. There is no easy way for the user to bring the login dialog to the foreground short of closing other windows that may be in front of it. Putting the form on the taskbar solves this. As a quick solution I looked at the SetMainForm method in the Vcl.Forms unit, and decided to extract the ChangeAppWindow() procedure since it is not available outside of the Forms unit. Then I simply called it from this event, and voila! a taskbar button showing the Login form.

procedure TfrmLogin.FormCreate(Sender: TObject);

I’m sure there are reasons why this method is not exposed as a public TApplication class procedure, but perhaps it could be with a usage caveat.

The Web vNext

Thursday, October 25th, 2018

I have been reading a lot about Web development lately, and pondering the future of web development.  For the longest time I shied away from Web development, largely because it was so laborious and frustrating.

I dabbled a bit back when people were using COM objects with VBScript on the server and Javascript on the client in classic ASP pages. Even back then, companies were making software look like Windows applications within the browser (IE).  By today’s standards, those applications look dated, but today’s web SPAs function in a similar manner, although great progress has been made in standardizing browsers, abstracting out their idiosyncrasies using frameworks, and handling variable display sizes.  My current experience is that it’s still harder and more time consuming to develop a good web application, and they are still not as rich as a Windows app IMHO.

That begs the question as to why people are writing applications for the web anyway.  For eCommerce sites, I get it, but for other line of business applications why not throw off the shackles of HTML/CSS and embrace a new UI framework altogether?  Now I know what you’re thinking…..this guy has lost it and wants to re-invent the web which a lot of smart people have worked on for years to make Web 2.0 a reality.  Before you call the white coats, read on…

When a user goes to a web site for any commercial activity they should be ensuring the website has a valid SSL certificate from a trusted authority.  The Internet is a dangerous place these days where web sites may be trying to attack your computer.  We download content from such sites into our sand boxed browser. This is not that much different than downloading a signed application.  We use signed applications all the time now, when using applications on our phones, tablets and desktops from the “app stores”.  The only difference is whether the store owner i.e.: Apple, has reviewed the application testing for malware.  Open source software such as Tortoise Git is often signed as well to ensure users trust that the application they are getting is from the advertised source and is safe to use.  I think it’s safe to say that most people would trust a signed application.

With that premise in hand, why aren’t we all writing signed Desktop apps using REST back ends?  Or if we really want to leverage single source cross platform applications, why not use WASM with a UI framework that allows an application to be written in languages that are typically used for native desktop, and mobile devices such as C#, Delphi, or C++?

The performance of even Javascript is pretty decent.  Many games have been ported to the browser using Javascript transpilers or EmScripten.  WASM allows developers to take this one step closer to the metal (CPU) and skip the run-time parsing and execution of Javascript.  Blazor is a project that does just that, within the confines of HTML/CSS, but also shows the possibility of using WASM with a different presentation framework such as Uno, or Ooui.  Obviously I’m not the only one thinking that a different presentation layer might be overdue in the web space.

One of the advantages of Blazor is to eliminate some of the third party dependencies, making the development stack more reliable, and to use the same technology and tools throughout.  Of course you can learn and use Javascript throughout the entire stack now, or a Javascript transpiler, but without WASM using your development language of choice is not possible.

I would like to see Object Pascal support the entire development stack.  Preferably the same language dialect and core libraries.  Perhaps something similar to Blazor, or maybe FMX targeting the web with WebGL.  All we need is to be able to capture the compiler IR and feed it into the WASM LLVM back end (okay there might be a little more to it than that).  The web is a huge horizontal market that is ripe for disruption and with the right moves, Delphi could grab a chunk of that segment, making the product relevant again.

What do you think is the future of Javascript on the web?  Will it be dethroned at some point by WASM? Is the future of the Web HTML/CSS, a different UI layer, or perhaps a mix depending on the type of web app?  Should I dust off the Delphi .NET compiler to generate MSIL to feed the Mono WASM run-time, or do we need a way to get the current compilers to output LLVM IR?

Maybe it’s just time to call the white coats as pondering all the options can drive you crazy…

Using a K750 Mac Keyboard with VMWare Fusion

Thursday, August 23rd, 2018

I just created a VM for the Beta test and decided I am going to use it on my Mac for a change. Rather than using a KVM I bought a Logitech M510 mouse, and K750 PC keyboard and bound it to one unifying receiver. Normally I just pull the USB receiver from my PC, put it into my Mac mini, switch the input on my display and I’m off to the races. This is not ideal in that some Mac keyboard mappings are then unavailable to me, but since I mainly run Windows VMs, that was okay until a leg broke on my PC keyboard.

I decided that I would start using my Mac K750, but re-discovered that the function keys are by default mapped to Mac OS/X special functions, and to use the function keys I had to press the fn + F which is a pain because of the location of the fn key and my muscle memory.

I tried using the tips on Malcolm Groves blog but without success as I am running High Sierra. I even installed Karabiner to remap the function keys to normal F keys and that didn’t seem to work for me. What did work was installing the Logitech Control Center. I didn’t have to re-map any keys it just worked…

I of course have VMWare Fusion 10’s Windows 10 Profile Keyboard mapping set to disable Mac OS Host keyboard shortcuts.

Now the only issue I have is that the Logitech M510 mouse does not track very well, and sometimes appears to lose it’s connection to the receiver.  If I lift it up and put it back down, I get my mouse cursor back, but it’s so frustrating I have started using an old Bluetooth Apple Mouse I bought at a garage sale for 25 cents.  Apparently Logitech is known for poor Mac support.

Why I Use(d) Still Use Delphi

Thursday, July 26th, 2018

I started using Object Pascal (Delphi) because it was VB like without the ugly syntax of VB, and it had the power of C++.   Namely that you could create as well as consume COM objects and it was natively compiled with at the time a very fast compiler when compared to C++.  The VCL was a stable UI framework that was simple to use and flexible enough that unusual use cases were still possible.

Sadly, now I use Delphi less and less and for maintenance work only, or personal and open source projects.  The community has dwindled from what it was once, local jobs are harder to find, and many luminaries have been lost to the evil empire (M$) and it’s technology.

I must admit that I am now working predominantly on C# .NET Core projects. I would gladly come back from the dark side if someone wanted to entice me with a interesting Delphi project. I find C# syntax more terse and unreadable than Object Pascal, but there is no mistaking the power of LINQ, the PPL, and the abundance of open source projects and technical resources. .NET native also makes adoption of C# even more tempting. If they can write Kestrel in C# you should be able to write anything that requires good performance in C#. I would love to see some Delphi web server benchmarks and how they compare to Kestrel. Favorable results might generate more interest in Delphi as would compiler benchmarks.

I love Delphi. I wish it a bright future.  Without new developers it will most certainly fade away over time.  New developers shy away from languages that won’t get them jobs.  An investment in learning a language, an IDE, and run-time libraries simply has to pay off.  Without a growing market share, expensive tools have to provide developers with a competitive edge. For this reason, I applaud EMBT’s release of the Community Edition. I hope it will bring new blood into the development community and spark more open source projects. There are some amazing open source projects out there that could use Community Edition to further their efforts.

There are also many exciting things happening in the land of Pascal that I hope will expand the community. REMObjects has released their Oxygene compiler that can also target WASM as well as native code. Smart Mobile Studio has released version 3 of their Pascal language targeting Javascript, and TMS has introduced a similar product called WebCore based on the FPC Javascript transpiler.  EMBT has hired Jon Aasenden and purchased Sencha so who knows what they have planned. With UniGUI and other frameworks Object Pascal (or rather different dialects) have many more options to target the web than only a couple years ago. I long for the day when I could use the same Object Pascal language for web, desktop, mobile and server development without compromising the results. Is it time for a language standard?