GraphQL from the perspective of a Delphi developer

Photo by Timothe Courtier on Unsplash

By now you probably know about GraphQL, or at least you might have read or heard that name somewhere. Wikipedia says that “GraphQL is an open-source data query and manipulation language for APIs, and a runtime for fulfilling queries with existing data”. If that doesn’t say much to you, or if you have read about GraphQL before but didn’t understand very well what it is, then this article is for you. Its purpose is to try – again – to explain what GraphQL is, its advantages and disadvantages, from the perspective of a Delphi (and also TMS XData) developer.

What is GraphQL?

There are plenty of articles explaining what GraphQL is. The official site, the Wikipedia article, tutorials here and there. So I will try to not be repetitive here and explain it my way, converting the points I was most confused of when I was learning about it. First of all:

  • GraphQL is NOT a framework or programming library;
  • GraphQL is NOT a server application;
  • GraphQL is NOT a database server or wrapper.

When I first started learning about it, this got me confused as well. What is GraphQL then?

  • GraphQL is a SPECIFICATION for a language and a runtime (available here).

In other words, GraphQL strictly specifies a query language and how runtime libraries should “execute” that language. Using a very rough analogy, it’s like a strict specification of SQL, explaining how SQL statements should be parsed and validated, and providing algorithms defining how database servers should execute those SQL and return data.

Of course, then you have several GraphQL implementations, which are indeed libraries in several different languages like Java, .NET, JavaScript, that allow you to create, for example, servers that, through HTTP, allow clients to send such queries and get the response of such query execution in JSON format. But note that even that HTTP communication is not strictly specified. It’s just one of many ways to “execute” a GraphQL document (a text file containing a query in valid GraphQL language).

GraphQL is “strongly typed”

This is one key point of GraphQL. Whatever you are going to do with it, you always start from a “schema”, which specifies all the types available in the language. The following is an example of a GraphQL schema:

type Query {
  human(id: Int): Human
}

type Human  {
  id: Int!
  name: String!
  homePlanet: String
  height: Float
  mass: Float
}

The above schema specifies two object types: Query and Human, the fields in each object type, and the type returned for each field. Fields can also have arguments (parameters), also with its specified type (human field in Query type has the parameter id of type Int).

If you are implementing a server that supports GraphQL, you have to define a schema first. If you are writing a client that sends GraphQL queries to a server, those queries must comply with the specified schema. You cannot create a query asking for a type that doesn’t exist. Or a field that doesn’t exist. Or even using a field parameter (argument) of a different data type than the specified.

It’s interesting to note that in a world that dynamic languages are so popular today (JavaScript being the main one), one of the key claims about GraphQL advantages is that it’s strongly typed – something I personally like, as a Delphi developer.

GraphQL documents (queries)

Once the GraphQL schema is defined, clients can write GraphQL documents (queries). In summary, a GraphQL query just lists the fields that we want the values for, and if such fields return objects, the fields of those objects, and on and on at any depth level you want. For example:

{
    human(id: 1000)  {
        name
        height
    }
}

The query above asks for the value of human field of type Query (implicit by default because of its name), passing the value 1000 for the id parameter. Since human field returns an object of type Human, the query also asks for just fields name and height for such object.

If such query is sent via HTTP to a server implementing GraphQL, the server will execute the query and return its results. A possible result could be something like this:

{
    "data": {
        "human": {
            "name": "Luke Skywalker",
            "height": 1.72
        }
    }
}

You get what you asked for: the result of human field, and the name and height fields of the Human object. It’s also important to explain two things:

  1. The GraphQL query is NOT a JSON document, even though it looks like one. It’s a GraphQL query, with its specific syntax as defined by the specification.
  2. The result data IS a JSON document, and the way it is formatted is NOT in the specification. It could be a XML document or whatever other format.

GraphQL and HTTP

GraphQL specification doesn’t say anything about HTTP. That really got me confused at the beginning, because I was reading all around about how GraphQL compares to REST, how it’s a new way to build APIs, etc. But the thing is GraphQL is not about HTTP, but only about the query language and how it should return results, in any format.

But of course, HTTP became the main way of executing GraphQL queries, and JSON end up being the most used format to return the results of such execution. The closest to a standard we have are some guidelines about how to serve GraphQL over HTTP, in the official GraphQL site.

In summary, there are no multiple endpoints: GraphQL queries are sent to a single URL endpoint, either directly in the URL in GET requests:

https://myapi/graphql?query={{human(id:1000){name,height}}

or in a JSON document, in POST requests:

POST /graphql HTTP/1.1
Host: myapi

{
  "query": "{{human(id:1000){name,height}}"
}

And the server response is usually a JSON document, as we saw above. It’s also interesting to note that if the GraphQL query is accepted, it always return an HTTP status code 200, even if the query execution fails. If there are errors, they appear inside the JSON document (error format is included in GraphQL specification):

{
  "errors": [
    {
      "message": "Cannot query field \"homePlanet\" on type \"Human\"."
    }
  ]
}

Why GraphQL?

Now that we have quickly covered what GraphQL is, it’s time to learn why it’s beginning to be so widely used.

There are several articles mentioning GraphQL advantages and disadvantages compared to REST, explaining why it’s taking over APIs, directly comparing GraphQL and REST, listing reasons why you should consider a GraphQL server and even how to convince your boss to use GraphQL (despite the awful name – in my opinion – this last one is a nice article about GraphQL).

I will try to summarize what I think are the key reasons. I will also try to compare it with REST and specially with TMS XData – a framework to build REST API servers using Delphi.

Clients choose what to fetch

In REST, if you want to retrieve an invoice, you will do something like this:

GET /invoice/10

{
  "id": 10,
  "total": 152
}

Then, if you want to retrieve the customer of the invoice, you need another request:

GET /invoice/10/customer

{
  "id": 115,
  "name": "Joe Doe"
}

Of course, your REST server could return customer data inline in the first request, when invoice is requested. But then, what if the client does not want customer data? The server will return more data than the client needs. In GraphQL you write the query asking just the data you want. Either without customer data:

{
  invoice(10)  {
    id
    total
  }
}

or with customer data:

{
  invoice(10) {
    id
    total
    customer {
      id
      name
    }
  }
}

And you don’t have to modify your server for that, or create multiple endpoints. Developing client applications with GraphQL, specially mobile and web applications, is a breeze, and performs very well – in a single request you get all the data you need, and only the data you need.

On the other hand, your REST server could implement mechanisms to allow your client to better choose what it needs. That’s what XData does, for example, with the $expand query filter mechanism. When an invoice is request from the client, it comes with minimum customer information (just the id):

GET /invoice/10

{
  "id": 10,
  "total": 152,
  "[email protected]": "customer(115)"
}

but if the client wants full customer information, he can just ask for it using $expand:

GET /invoice/10?$expand=customer

{
  "id": 10,
  "total": 152,
  "customer": {
    "id": 115,
    "name": "John Doe"
  }
}

When I first learned about GraphQL, my thought was: this might be an advantage in some situations, but if you are using a XData REST server, it’s not a big difference. With XData, there are ways to get all related (associated) information in one single server request (roundtrip).

Schema introspection (Self-documentation)

As I’ve mentioned above, GraphQL is based on a schema which holds information about all types, fields and other elements needed to describe and validate a GraphQL query. Not only that, GraphQL itself provides a way for clients to retrieve information about such schema, a process called introspection. For example, this query will ask for all fields of the type Human, with their respective types:

{
  __type(name: "Human") {
    name
    fields {
      name
      type {
        name
        kind
      }
    }
  }
}

The query would return something like this:

{
  "data": {
    "__type": {
      "name": “Human”,
      "fields": [
        {
          "name": "id",
          "type": {
            "name": null,
            "kind": "NON_NULL"
          }
        },
        {
          "name": "name",
          "type": {
            "name": null,
            "kind": "NON_NULL"
          }
        },
        {
          "name": “homePlanet”,
          "type": {
            "name": "String",
            "kind": "SCALAR"
        },
        {
          "name": “height,
          "type": {
            "name": “Float,
            "kind": "SCALAR"
        },
        {
          "name": “mass”,
          "type": {
            "name": “Float”,
            "kind": "SCALAR"
          }
        }
      ]
    }
  }
}

This brings a lot of benefits. First, all clients know in advance what information they can retrieve. That also means that a GraphQL server is self-documented, since the schema already describes what it can offer.

For a client to use a REST server, for example it necessarily needs to go to some kind of documentation, because the client simply don’t know that an invoice resource is available at some endpoint /invoice/:id, or what is the type of the id, or any other ways to create an invoice, different ways to query, etc. That’s not the case with GraphQL: everything is there.

Also, this makes it possible to create lots of tools around GraphQL. I will mention it later in this article.

Again, REST servers also have a nice way to provide meta information about it: Swagger. The problem, of course, is that not all REST servers implement Swagger. Also, some REST implementations require you to do lots of extra coding to properly build the Swagger file, like adding lots of attributes just to flag each endpoint, which parameters are available in each endpoint, etc.

Luckily, TMS XData does support Swagger beautifully, and in a very automatic way. Basically, after you created your REST API with XData, your Swagger document is provided automatically, because it has all metadata information from the interfaces declared as endpoints, thanks to the way XData is built. So the “introspection” of a XData REST server can be enabled with just a few lines to code, and available at a single endpoint:

https://myapi/openapi/swagger.json

Again, this is a nice GraphQL feature, but with proper tool or effort, REST servers can also provide such mechanism.

Versioning

From GraphQL website: Why do most APIs version? When there’s limited control over the data that’s returned from an API endpoint, any change can be considered a breaking change, and breaking changes require a new version. If adding new features to an API requires a new version, then a tradeoff emerges between releasing often and having many incremental versions versus the understandability and maintainability of the API.

In other words: it’s easier to expand and evolve a GraphQL API because clients never receive information that they didn’t ask for. Adding a new field to Human type, for example, will be harmless because existing clients will never receive that new field, because they never asked for it. On the other hand, adding a new field to a REST endpoint will result in a different response for existing clients (the new added field).

Thus, GraphQL makes it easier to evolve your API and, in theory – in most cases, not all – you don’t need to version your API.

Tools and libraries

In my opinion, this is where GraphQL really shines, and which justifies using it. As you saw, when you use nice libraries for building REST servers, like TMS XData, you kind of minimize the advantages of GraphQL over REST. The limitations of REST are known, and a good framework, over time, will add features to solve the problems. That’s what XData does.

But when you have an ecosystem, it’s a different thing. You can’t control or define everything that will be built around a tool or a specification. Since the release of GraphQL, lots of tools and libraries have been built, and once you have your GraphQL API, you can benefit from all of them.

This nice article describes 10 awesome tools and extensions for GraphQL APIs, and I will explicitly mention some of them here.

GraphiQL and/or GraphQL Playground

Simply put, GraphiQL and GraphQL Playground are a “GraphQL IDE”. From there you can write your queries with full code completion (GraphQL has a schema, remember?), syntax check, detailed error messages and positions, among others. It really makes it easy to write and run GraphQL queries.

GraphQL Voyager

GraphQL voyager is a tool to represent any GraphQL API as an interactive graph. Another tool that takes advantage of the GraphQL schema introspection. You quickly see all your schema in a graphical way, and how each field and type relates to each other. It has a nice live demo you can try.

Browser extensions

There are several GraphQL extensions to your favorite browser that helps you out when building web applications that connect to GraphQL. Both Chrome GraphQL Network and Firefox GraphQL DevTools extensions are valuable tools that allows you to debug, inspect requests, track errors and increase your productivity when working with GraphQL. They are just honorable mentions, of course there are much more extensions for different purposes that you can use.

Clients all around

This deserves a separated article, but of course it’s worth mention that libraries for GraphQL clients are all around. If you want to build web or mobile applications, there are clients for React, VueJs, Angular, Swift, Kotlin, Flutter and many other development tools and libraries.

Final notes

I didn’t name this section “Conclusion” because there is nothing to conclude. This article also didn’t have an intention to compare GraphQL with anything – even when I do comparisons with REST here and there.

The idea was to introduce this technology to newcomers, and also for those who already knew about it, talk about it from the perspective of a Delphi developer, hoping that I had clarified some points that might be obscure for those used to Delphi – I tried to focused exactly on the points that got me confused when I started learning about GraphQL.

What about you? Do you have any experience with GraphQL? Are you using it in production? What do you think about it? Are you a newcomer and want to ask something or share your doubts? Please leave your comment following the link below and let’s discuss about it!

Catching memory leaks in Delphi: a definitive list of tools

Photo by Hunter Haley on Unsplash

Detecting memory leaks is a very important task in Delphi development. I’ve written about it before, stressing that in server applications like the ones built with TMS XData this is even more important.

With the upcoming release of Delphi 10.4 version, this will become even more relevant. A unified memory management has been promised since last year, and it looks it has arrived.

As everything in life, this change isn’t 100% good or bad, there are pros and cons in it, but one thing is clear: the way memory is managed now is the same in all platforms, so the ways to detect memory leaks in different platforms are more similar now. I personally think this is a good thing. It’s also important to note that this doesn’t necessarily mean “more leaks” in mobile platforms. The “old” (still valid when I’m writing this article) ARC mechanism also had its problems, and in my opinion harder to detect, like dealing with cyclical references.

But well, enough with this too long introduction. The humble purpose of this article is to be a definitive and up-to-date list of all tools that you can use to detect memory leaks in Delphi applications. Pointing out that memory management is unified just means that these tools are even more relevant than ever. Detecting and fixing a memory leak in Windows will help even more that your non-Windows applications will not have memory leaks as well.

So, to the list!

FastMM (Free)

FastMM (or to be more specific, FastMM4) is the de-facto standard tool to detect memory leaks in Delphi. The reason is simple: it’s the default memory manager in Delphi, so it’s already built-in and ready to use.

Since FastMM allocates and deallocates memory in your application, who else is better to report the blocks that have not been deallocated? All that it takes to start working with it is add a single line in your project:

ReportMemoryLeaksOnShutdown := True;

And voilà, your application will report all memory leaks when it shuts down. If there are leaks at the end of your application, a dialog will be displayed showing all the leaks.

All Delphi developers should add that line to their applications. Really. I don’t even know why this is not added by default in Delphi, at least wrapped by a {$IFDEF DEBUG} directive. Maybe for historical reasons.

So, if it’s built-in, default, works, why don’t we finish this article here, then? Well, there are some gotchas.

Delphi includes a stripped out version of FastMM4. It doesn’t have all the nice debugging tools you need (to know, for example, where in the code your leaked memory was allocated). To do that, you have to use the full FastMM4 version, available on the FASTMM4 public GitHub repository.

You also have to use a DLL for the full debugging features; it’s not cross-platform: it only officially works for Windows (it looks like a macOS version is available in the official repo, but I never tried it). And even though it has lots of features, to use it you have to deal with .INC files and manual configurations to make it work, which might not be comfortable for some users.

But all in all, is a great tool, the “standard” tool to get memory leaks in Delphi. (Side note: FASTMM5 has just been released. We haven’t tested it yet but it looks like it brings a great improvement in performance for multithreaded applications, we can’t wait to test it in TMS XData.)

Pros

  • Free;
  • Full source code;
  • Built-in in Delphi;
  • Easy to setup;
  • Lots of advanced features.

Cons

  • Windows only;
  • Needs external DLL for debugging features;
  • Not user-friendly to setup and use advanced features (no built-in GUI);
  • Only reports leaks on memory allocated by FASTMM itself.

LeakCheck (Free)

Delphi LeakCheck is another great option for detecting memory leaks. It’s also free, open source, and has some advantages over FastMM: it’s cross-platform, meaning you can check leaks directly in mobile and Linux applications; and it integrates very well with unit test frameworks (namely DUnit and DUnitX).

The way to get started with it is similar to FastMM: add LeakCheck unit as the first used unit in your dpr uses clause, and it will plugin and be ready to use. Setting up for unit testing is a little more complicated though, but that’s part of the game.

One small disadvantage is that to use it you are almost on your own: the project hasn’t received updates for a while (which isn’t necessarily bad since it’s working). But that means probably you won’t get much help directly from the author (I never tried, to be fair). There is also not much information about it in the web, I just found one single article that explains how to use it besides the detailed description in the official Bitbucket repository itself.

Pros

  • Free;
  • Full source code;
  • Cross-plataform;
  • Integrates well with unit testing (DUnit and DUnitX).

Cons

  • Not much information around about how to use it;
  • No recent updates, no official support;

Deleaker (Commercial)

Delaker is the only commercial tool in the list that is exclusively dedicated to catch memory leaks. That reflects in the product, which provides you with really nice features for detecting memory leaks.

Differently from the previous two tools, and similar to the following ones, it has a friendly GUI for you to setup the environment and see the results, which can be used standalone or integrated to Delphi IDE. It can also detect way more types of memory leaks: GDI leaks, leaks of Windows USER objects and handles, leaks in Windows APIs, in 3rd party DLLs, etc. Exactly because of that, it provides options for you to easily ignore several types of leaks – if you don’t, you will get a gazillion of leaks in just a regular app execution.

Another nice feature is the ability to take snapshots of the memory allocation. This allows you to detect leaks not only during the lifetime of your whole application, but in some specific operations of it.

Pros

  • Friendly GUI that can be used standalone or integrated into Delphi IDE;
  • Detects all types of leaks;
  • Command-line tool for CI integration;
  • Memory usage snapshots;
  • Official support;

Cons

  • Paid license ($99 for Home License, $399 for Single Developer License);
  • Windows only;

EurekaLog (Commercial)

EurekaLog is an old player. It’s been around for decades – I couldn’t find any info on their web site about when first version was released, the oldest information is for EurekaLog 4.0 which was released in 2002, simply 18 years ago.

It’s not a tool dedicated exclusively to catch memory leaks. Instead, it has a full range of features, memory leak detection being just a “side” feature. The purpose of EurekaLog is to detect any problems in your application – exceptions, leaks, etc. – at the customer side, and report it back to you.

Thus, it’s a great tool to help you improve the quality of your software and provide good support to your customers, since you will get error and leak reports from all your customers, in different environments, doing different operations. It also helps you to find tricky bugs that only happen at customer side (you know it well, those “cannot reproduce it here” situations).

Pros

  • Detects both memory and resource leaks;
  • Leaks and errors detected at customer side can be sent automatically to you;
  • Lots of other features: bug reporting, integration with bug tracking systems, among others;
  • Official support;

Cons

  • Paid license ($149 for Professional License, $249 for Enterprise License);
  • Windows only;
  • Not many advanced features for memory leak detection;

madExcept (Commercial)

I use to say that MadExcept is the “cousin” of EurekaLog. They are both available for about the same time (around 20 years or more). They share similar features. They have more or less the same purpose. And so on.

And, funny enough, there isn’t a “winner”. If you look around the web about comparisons between the two, you will never come to a conclusion on which is “better”. Customers of both products are usually satisfied, and also usually they can’t comment on the competitor because they never used it. That’s my case, actually. I’m a happy EurekaLog customer (although I don’t use it to catch memory leaks), and I never used madExcept. But it could simply be the opposite. I believe I could be well served with madExcept as well.

Thus, I considered madExcept pros and cons equal to EurekaLog’s. Maybe the only visible different is that while madExcept is cheaper (there is even a free version for non-commercial use), EurekaLog seems to be much more active and frequently updated.

Pros

  • Free for non-commercial support;
  • Detects both memory and resource leaks;
  • Leaks and errors detected at customer side can be sent automatically to you;
  • Lots of other features: bug reporting, integration with bug tracking systems, among others;
  • Official support;

Cons

  • Paid license (€ 159 for full source license);
  • Windows only;
  • Not many advanced features for memory leak detection;

AQTime Pro (Commercial)

AQTime is a top-notch tool to make your code better. It’s really high standard, offering not only an advanced memory leak detection tool (with a nice GUI, snapshots, memory tracking, resource leaks detection, among others) but also performance profiling (with both instrumenting and sampling profilers), code coverage, code analysis, among others.

It’s really awesome tool, but it has its downsides: it’s pretty expensive, and it looks in “maintenance” mode – it receives updates more or less once a year, and the news are mostly “support for the new Delphi version”. Handful bug fixes over the years, and virtually no new features. But well, it still has no equivalent tool in Delphi world when it comes to many and powerful features.

Pros

  • Detects memory, resource, GDI, handle leaks among others;
  • Real-time allocation monitor;
  • Snapshots;
  • Lots of other tools in the bundle (performance profiler, code coverage, etc.).

Cons

  • Pretty expensive ($719 for a node-locked license, $2279 for node-floating license);
  • Windows only;

Nexus Quality Suite (Commercial)

In a similar way of EurekaLog and madExcept, I believe Nexus Quality Suite is somewhat related to AQTime. Both provide lots of tools to improve the quality of your software, and there are intersections between them.

Nexus Quality suite provides memory and resource leak detectors, but also performance profilers, line timers, code coverage, and even a GUI automatic tester, among other things.

I haven’t tried the memory check tool myself, thus the pros and cons will be just based on what I see from web site:

Pros

  • Detects memory and resource leaks;
  • Official support, active support forums;
  • Lots of other tools in the package

Cons

  • Paid license (AUD 490, around $300);
  • Windows only.

DDDebug (Commercial)

From their website: DDDebug is a collection of debugging tools which contains several modules: a memory profiler, a thread viewer, a module viewer and an enhanced exception handler.

One interesting thing I noted from DDDebug is that it has a slightly different approach, by providing memory usage and statistics instantly from inside the application. I didn’t use it but it looks like it makes it easier to find bugs in the app, by interacting with it at the same time you analyze it.

It also works with packages which is a plus, provides more functions besides just memory leak detection, and even though it’s commercial, the license price is really accessible.

Pros

  • Provides results directly inside your application, from a GUI;
  • Supports packages;
  • Official support;
  • Accessible license price (from €59).

Cons

  • Windows only;

Spider (Free)

Spider websites lists a lot of interesting features: analysis of exceptions, analysis of the realtime use of memory, analysis of memory leaks, analysis of the call stack, among others.

The thing is, from the list, is a tool I just tried once, and I got confused with the user interface and the results themselves. I couldn’t use it, but maybe that’s just me. So it’s listed here, but I can’t make any fair judgement over it.

Pros

  • Free;
  • Source code available;

Cons

  • Confusing user interface (personal opinion);

Non-Delphi Tools

In addition to the above tools that are Delphi specific, or at least also cover Delphi specifically – either integrating into source code, or in the IDE, etc. – there are also general-purpose tools for memory leak detection which can be helpful in some situations.

Valgrind (Free)

Valgrind is an instrumentation framework. It provides many tools in it, and you can add your own. One of the tools is memcheck, which will help you to get leaks in your application.

I use it myself a lot to detect memory leaks in Linux applications, and it’s actually very simple to use: just execute valgrind and pass the application you want to test in the command-line parameter. Valgrind will launch the application and at the end of it will give you a report with detailed information including possible leaks. There are of course many command-line options you can use to log to a file, choose the size of call stack, detection level, among others.

Instruments (Free)

Apple Instruments is a powerful and flexible performance-analysis and testing tool that’s part of the Xcode tool set. Among other things, it can be used to detect leak in iOS and macOS applications. Adrian Gallero has made a nice article at TMS Software blog about how to use Instruments to detect leaks in iOS applications. It’s a little bit old post already, but I believe it’s still valid.

Conclusion

There is no winner. Each tool has their own pros and cons, and it’s interesting to note that the they are not mutually exclusive. Actually, I use several of them myself, for different purposes.

I use FastMM for my “daily” memory leak detection, LeakCheck in unit tests, Deleaker when I want to check for other types of leaks and use snapshots, EurekaLog for bug reporting in my end-user applications, AQTime for performance profiling and Valgrind for detecting leaks in Linux. As you can see, all of them are useful!

The important thing is: don’t let your application leak memory! If you are just starting with this subject, you know what to have to do now:

ReportMemoryLeaksOnShutdown := True;

Add the above line to your application and start catching leaks!

(Do you know of any other tool that should be on the list? Do you have a different opinion on the listed tools? Please comment below and share your knowledge to help make this list the definitive one. I will update it frequently as I receive new info.)

An interesting discussion about data replication with TMS Echo

This one is another one of many interesting discussions we had at the TMS Business Masterclass in Düsseldorf. One of then was the funny discussion about class fields having their name prefixed with uppercase “F” or not.

Now this one is a little bit more technical, but also interesting nonetheless. The session was about database data replication using TMS Echo, and the topic was how the changes are send (moved) from one peer (node) to another.

The question raised was about the “server”, or the “controller” which orchestrates all this “moving” of data changes. I replied that there is no “server” (in the sense that there is no central orchestrator, the system is distributed and can operate independent from other nodes), only to contradict myself few minutes later saying that a “server” is needed (but then I – hopefully – explained the contradiction).

A funny and interesting discussion, I hope you enjoy it, and, after you watch the video, I raise the question to you: Is there a server, or not? Leave your comment!

By the way, the complete content of the event is available here: TMS Business Masterclass Online.

TMS Business Masterclass is now online

TMS Business Masterclass Course

In November 2019, TMS Days 2019 took place in both Düsseldorf, Germany and Wevelgem, Belgium. It was the biggest TMS event ever, with three full days in two different cities, and team members from nine different countries around the world.

It was a face-to-face event and even before the event started many people from all over the world approached us asking if they could watch the content online since they could not travel to attend the event in person.

TMS Business Masterclass Wevelgem

Well, now also for the first time, parts of a TMS event is now available to be watched online. You will have the opportunity to watch both TMS Business Masterclass days in full length – the one which took place in Düsseldorf and the one which took place in Wevelgem.

We also tried to provide you with high quality material:

  • Audio from instructor is clear and the screen recordings are there, of course;
  • A second camera showing the instructor is also present to give you a more immersive feeling and get a more personal touch;
TMS Business Masterclass Instructor
  • Questions from the audience was not very audible, but we took the effort to subtitle most of the questions so you could follow and understand everything that was being discussed!
TMS Business Masterclass Subtitles
  • The full recording was fully reviewed and broken into several smaller pieces, so you don’t have a big chunk of 8 hours recording, but very small “lessons” and the subject discussed in each of them. Some are broken to the length of only a few minutes. So you can get really focused and productive on finding content!
TMS Business Masterclass Curriculum

Follow the links below to get more info about the course, pictures of the event, view the full course content structure, watch some preview videos for free, and of course, enroll to the course!

TMS Business Masterclass in Düsseldorf ($49)

TMS Business Masterclass in Wevelgem ($49)

TMS Business Masterclass Bundle ($79)

Enrollment is $79 for both courses, or just $49 for one course. Of course, all the attendants of the event in Düsseldorf or Wevelgem get free access, not only for the attended day, but for both. Another perk for the attendants!

To finish this post, watch this personal-favorite excerpt below. When building Delphi classes, do you prefix field names with an uppercase “F”? 😉

The Biggest TMS Software Event Ever

Be prepared! Coming in November 2019, the biggest TMS Software event ever: TMS TRAINING DAYS 2019. TMS team members from nine different countries will be speaking about Delphi development, TMS libraries and components, in sessions that target from the beginner developer to the advance one.

Dusseldorf Training Days (Germany)

On November 14th and 15th, there will be two training days in Dusseldorf, Germany. The event will take place at Lindner Hotel Airport, Unterrather Str. 108, 40468 Düsseldorf, Germany.

Check below the full agenda for the two training days

TMS Business Masterclass
November, 14th – Dusseldorf, Germany

Bruno Fierens

9h00: Welcome & introduction (Bruno Fierens)
A welcome to all attendees and introduction to the agenda.


Wagner Landgraf

9h15: Session 1 – The TMS Business World (Wagner R. Landgraf) 
A journey into the world of TMS Business bundle. We will learn about the solutions provided by TMS Business: the components included, the libraries, the use cases, all in the historical context and the motivations behind it. Products covered: TMS Scripter, TMS Diagram Studio, TMS Workflow Studio, TMS Data Modeler, TMS Aurelius, TMS Sparkle, TMS RemoteDB, TMS XData, TMS Echo, TMS Logging. 
*BIZ level: Beginner 


10h00: Coffee break


10h30: The TMS Aurelius book , experiences & book writing process (John Kouraklis)
John Kouraklis book author talks about his most recent book dedicated to TMS Aurelius and the experiences related to writing it.


Wagner Landgraf

11h00: Session 2 – The Joy of Databases (Wagner R. Landgraf) 
A talk about new ways to deal with databases. What is an ORM (Object-Relational Mapping) framework, and are the most recent news and features about it. What you can use to help you out in modeling your databases, easily use existing databases with the new paradigm, and advanced techniques on ORM and database modeling. Products covered: TMS Aurelius, TMS Data Modeler 
*BIZ level: Intermediate 


Wagner Landgraf

12h00: Session 3 – Your App Everywhere: REST API (Wagner R. Landgraf) 
Multitier, cloud, REST, HTTP, SSL: What, Why, When, and mainly, How? Learn what a REST API server means, why you will benefit from moving your app to the cloud, and learn how to do it in a very RAD way. The latest features will be covered, even for the experienced users. Products covered: TMS XData, TMS Sparkle 
*BIZ level: Intermediate 


13h00: Warm lunch


Wagner Landgraf

14h00: Session 4 – The Unsung Heroes (Wagner R. Landgraf) 
A deeper look into three awesome TMS Business libraries that bring you solutions for problems you never thought you had. User-customized application, modifying business rules at runtime, offline data synchronization, and moving your app to the cloud in a couple of days. Products covered: TMS Scripter, TMS Echo, TMS RemoteDB 
*BIZ level: Beginner 


Wagner Landgraf

15h00: Session 5 – Getting serious in the Cloud (Wagner R. Landgraf) 
Advanced techniques and concepts when building REST API servers: Security, background processing and deep analysis of real-world source code. Products covered: TMS XData, TMS Sparkle 
*BIZ level: Advanced 


16h00: Coffee break


Wagner Landgraf

16h30: Session 6: All Together Now (Wagner R. Landgraf) 
A very interactive session where all the current ideas from the TMS team for the future of TMS Business will be presented. We will discuss the existing roadmap, brainstorming about all the possibilities, have all questions answered and summarize the whole day. 


17h30: Wrap-up, Q&A & open discussion 


TMS DEV Intensive
November, 15th – Dusseldorf, Germany

Bruno Fierens

9h00: Welcome & introduction (Bruno Fierens)
A welcome to all attendees and introduction to the agenda.


Bruno Fierens

9h15: TMS VCL UI Pack modernization (Bruno Fierens)
What is new & upcoming for ensuring VCL UI controls look as good as possible: high-DPI, VCL styles, Office styles, images


Marion Candau

10h15: Using TMS Cryptography Pack for secure signing of PDF files (Marion Candau)
Marion will show how to sign a PDF document with a cryptographic USB token using TMS Cryptography Pack. She will briefly explain the cryptographic mechanisms of an electronic signature, then she will present how a cryptographic USB token works and finally, how to use a TMS Cryptography Pack component to sign a PDF document with the token. 


10h45: Coffee break


Adrian Gallero

11h15: TMS Flexcel 7.0 introduction: taking advantage of the new Flexcel 7.0 for VCL/FMX features (Adrian Gallero)
Adrian will show how to create a Delphi app that exports data to Excel and Pdf files, using some of the newest stuff introduced in FlexCel 7. If time allows, he will also have a glimpse at the future and look at the stuff currently in development.


12h15: Warm lunch


José León Serna

13h15: Taking the wraps of our upcoming groundbreaking product for Delphi developers (José León Serna / Bruno Fierens)
Be there, be amazed, receive the first product beta and start playing with it!
It has been more than one year that Bruno Fierens, CEO of tmssoftware.com got in touch with José Leon Serna and discussed about future opportunities for Delphi development. Surprisingly our visions for future directions and possibilities perfectly aligned. From there, an intense collaboration started and in this session they will present the first fruits of this collaboration. TMS clearly could not have achieved the amazing technical break-throughs without José Leon. The TMS team is honoured, happy and proud to have one of the brightest minds in the Delphi world in our family.


Roman Yankovsky

14h15: Using TMS FixInsight to bring your code to a higher & more secure level (Roman Yankovsky)
Roman will show how to use FixInsight’s static code analysis in Delphi to find bugs in your code before your customers do.


15h15: Coffee break


Roman Kassebaum

15h45: TMS WEB Core v1.3 for web, cross platform Electron and mobile PWA apps new features & capabilities (Bruno Fierens / Roman Kassebaum)
Together with Bruno Fierens, Roman Kassebaum, architect of the TMS WEB Core IDE integration, will present and demonstrate TMS WEB Core v1.3 new features & capabilities.


Holger Flick

16h45: Putting it all together : Using TMS XData back-end and TMS WEB Core + TMS FNC UI as front-end (Holger Flick)
Many frameworks, many platforms: TMS has all the tools. You’ve read it many times, but how do all these technologies fit together?
This session will give an example of how you can build a database application for multiple desktop and mobile platforms as well as for the web using the same database backend. It will also provide an overview of the technologies that are available from the TMS toolbox and will hand you key pointers how to pick the right one for the task you need to achieve. In short, you will get a hands-on example that covers TMS XData, TMS RemoteDB, TMS Web Core, VCL, and FNC.


17h45: Q&A & open discussions 


Meet the experts

During the whole TMS Dev Intensive Day, the opportunity will be given, as alternative to the regular sessions, to meet each of the many TMS experts available during the full day in person or in very small group to discuss and learn from. 

Wevelgem Training Day (Belgium)

On November 18th, there will be a second TMS Business Masterclass day in Wevelgem, Belgium. The event will take place at the TMS Software Main Office. It’s an opportunity to meet other members of the team as well!

The sessions will very similar to the TMS Business Masterclass in Dusseldorf on November 14th, thus this is a simplified agenda. All sessions will be presented by Wagner Landgraf and Bruno Fierens.

TMS Business Masterclass
November, 18th – Wevelgem, Belgium

Speakers:

Bruno Fierens
Wagner Landgraf

9h00: Welcome & introduction (Bruno Fierens)


9h15: Session 1 – The TMS Business World (Wagner R. Landgraf) 


10h00: Coffee break


10h30: Session 2 – The Joy of Databases (Wagner R. Landgraf) 


11h30: Session 3 – Your App Everywhere: REST API (Wagner R. Landgraf) 


12h30: Warm lunch


13h30: Session 4 – The Unsung Heroes (Wagner R. Landgraf) 


14h30: Session 5 – Getting serious in the Cloud (Wagner R. Landgraf) 


15h30: Coffee break


16h00: Session 6: All Together Now (Wagner R. Landgraf)  


17h00: Wrap-up, Q&A & open discussion 


SPEAKERS

Adrian Gallero (Uruguay)

Adrian Gallero is an Electrical Engineer who has been working in Delphi since it was Turbo pascal 4. He has worked in calculating power line distribution for electrical companies in Montevideo and Rio de Janeiro. He lived for over 3 years in Madrid working the development of a telecommunication management system, and over a year in Sydney developing custom solutions for a freight-forwarding company. 

He has been working with spreadsheets for longer than he can remember, and in 1996 he developed a small component that allowed his Delphi 1 apps to export the results to a spreadsheet (to his surprise, he learned a year ago that the electrical company is still using those unmodified apps today). This component grew over the years: It was renamed FlexCel in 2001 and it joined the TMS family in 2002. Today FlexCel exists in both Delphi and .NET versions, and they contain over a million lines of code. 


Bruno Fierens (Belgium)

  • Studied civil electronic engineering at university of Ghent, Belgium (1987-1992).
  • Started a career as R&D digital hardware engineer at Barco Graphics Belgium designing with FPGA, VHDL, graphic processors, PCI, Silicon Graphics add-on boards, high-end printer controllers,…
  • Began writing software in Turbo Pascal 3.0 since 1987 and used all Borland Pascal and all Delphi versions since then.
  • Founded TMS software in 1996, developing VCL components starting with Delphi 1.
  • TMS software became Borland Technology Partner in 1998 and developed Delphi Informant award-winning grid & scheduling components.
  • From 2011 FireMonkey cross platform components,targetting Windows, macOS, Android, iOS.
  • In 2016, TMS software launched FNC, a framework neutral component architecture enabling to use UI controls in VCL,FMX & LCL apps
  • In 2018, TMS software launched TMS WEB Core, a framework for creating rich web clients using ObjectPascal
  • Currently doing and managing VCL, FMX, Web, .NET, IoT, LCL, REST, node.js development.
  • Is a regular speaker at conferences (Be-Delphi, DelphiTage, ITDevCon, CodeWay Tour, EKON, DevTracks, SDN, ..).
  • Available for consulting & custom project development.
  • Bruno Fierens was titled Embarcadero MVP since 2012.
  • Special area of interest are user interfaces design, UX, RAD software development, hardware/electronics.

Holger Flick (United States)

Since 1996, Dr. Holger Flick has been using Delphi as his primary development platform and has been an active member of the community. He studied computer science at Dortmund University and later wrote his dissertation at the Ruhr University in Bochum in the field of telemedicine. For his passion for and knowledge of Delphi he was awarded the “Delphi MVP” moniker in 2016. 

In 2019, Holger moved to the United States of America (USA) and established his new company FlixEngineering LLC. The company focuses on consulting, training and software development using object-oriented programming languages like Delphi, C#, Swift, and Objective-C. 
Holger is part of the TMS Software family providing his expertise as Evangelist and QA Engineer. 


John Kouraklis (United Kingdom)

John Kouraklis started exploring computers when he was 16 and since then has followed all the way from Turbo Pascal to the latest Delphi versions as a hobby initially and as a profession for most of his adult life. He has developed a wide range of applications, from financial software to reverse engineering tools. The last years he has been teaching business and programming in undergraduate and postgraduate courses. He is the author of MVVM in Delphi (Apress, 2016) and Introducing Delphi ORM – ORM with TMS Aurelius (July 2019)


José León Serna (Spain)

Creator of Delphi for PHP/HTML5 Builder and former Director of Engineering and Branch Manager at Embarcadero Technologies between 2010 and 2016. Although the Embarcadero’s branch participated in the development of several products, he was mainly responsible for RAD Studio, and more specifically, the IDE. He participated actively on the conception and implementation of multitude of new features, specially focused on multi-device development. He has been involved in IDE development for most part of his career and is the area where he enjoys most. 


Marion Candau (France)

  • PhD in cryptography
  • Developer at Cyberens, a French cybersecurity company located in Bordeaux. 
  • TMS Cryptography Pack architect
  • MVP Embarcadero
  • She mainly develops cybersecurity-related applications and advises clients to use cryptographic tools and libraries in their own applications.

Roman Kassebaum (Germany)

Roman Kassebaum is a freelancer. He started to work with Delphi in 1996 after he graduated with a Master degree from the University of Paderborn. He is a Delphi MVP and an Embarcadero Technology Partner. During the last years he became a member of the great TMS team and he is also a  TMS certified consulting partner. Roman is a specialist in all kinds of Delphi projects including TMS Business components and the cutting edge TMS WEB Core library for which he created the Delphi IDE integration. 


Roman Yankovsky (Russia)

Roman Yankovsky is an Embarcadero MVP who has been working with Delphi since Delphi 2. He joined the TMS team in 2016. He is the product manager and architect of the  FixInsight static analysis tool for Delphi. 

Roman Yankovsky is also author of the Delphi AST, an open source Abstract syntax tree builder for Delphi you can find here: https://github.com/RomanYankovsky/DelphiAST and this library is used in the great OmniPascal Visual Studio Code extension.


Wagner Landgraf (Brazil)

  • Graduated in Electronic Engineering and M.Sc in Industrial IT at Federal Technological University of Parana-Brazil.
  • More than 24 years experience (since 1995) in Delphi development – since Delphi 1.
  • Architect and main developer of Delphi libraries like TMS Aurelius, TMS XData, TMS RemoteDB, TMS Scripter, among others.
  • Product Manager at TMS Software for more than 20 years.
  • Founder of landgraf.dev online school.

Special Bonuses

There are also special bonuses for attendees of TMS Training Days!

Book: Introducing Delphi ORM

All attendees of TMS Business Masterclass day in Dusseldorf (Nov 14th) will receive a free copy of the book “Introducing Delphi ORM: Object-Relational Mapping using TMS Aurelius“, written by John Kouraklis. Wagner Landgraf, author of TMS Aurelius was a technical reviewer of the book.


“Introduction to TMS Web Core” Training Course: 50% off

All attendees of TMS Training Days will get a 50% off discount coupon for the online training course “Introduction to TMS Web Core”, from landgraf.dev. The instructor is Wagner Landgraf and you will learn concepts from the beginning: what is a web application, how does it work, what are single page application (SPA) and multiple page application (MPA), what is HTML, JavaScript, CSS, Bootstrap, AJAX. Full source code of the examples are provided.


Special discounts for TMS Products

TMS Software will also offer special discounts for new license on several TMS products, for all attendees. Stay tuned for the offers!

Registration and More Info

You can find more info from TMS Software web site directly: TMS Training Days in Dusseldorf and TMS Business Masterclass in Wevelgen.

Registration fees:

Nov 14th, TMS Business MasterClass: 295 EUR 
Nov 15th, TMS Dev Intensive: 295 EUR
Nov 18th, TMS Business Masterclass: 295 EUR

Special offer for the two TMS Training Days in Dusseldorf (Nov 14th and 15h): 495 EUR 

Embarcadero Conference 2019 in Brazil: Meet the NFC-e Issuer in the Cloud

On October 22nd, 2019, there will be another edition of Embarcadero Conference. It’s the biggest Delphi event of the world, and happens in São Paulo, Brazil. There are hundreds of attendants.

In this edition, just like last year, there will be seven simultaneous sessions, all happening in the same auditorium. You choose which session to listen by selecting the audio channel in your headphones. The full session list is available in the site of the event.

With som many sessions happening at the same time, you get even anxious to choose which want to watch. But if there is one that you cannot miss, it’s this one we are going to suggest.

Our speaker, Wagner Landgraf, will be presenting the session “Anatomy NFC-e issuer in the cloud (REST API). Oh yes, we are recommending our own session. But that’s just a coincidence, it will be very interesting, believe me!

Why “in the cloud”?

Ok, let’s anticipate some content here. Why of the reasons is the “why”. NFC-e is a legal digital document in Brazil, and when we issue such a document in the cloud, we have several advantages compared to the issuing of the same document in a local desktop or mobile application:

  • One single and centralized place to configure the issuing environment (installation of certificates, configuration of cryptography libraries, etc.)
  • Minimizes the risk of problems and support cost: you don’t have to configure hundreds of client environments
  • Much easier system update and maintenance: you also don’t need to manage all the clients.
  • You can issue NFC-e from any platform (from a desktop Windows application, a mobile application, or even from Rasperry PI, who knows?). All you need is internet connection and HTTP communication on that platform.
  • It’s easier to develop clients in other platforms. No need to be able to port and compile several 3rd party libraries needed for the document issuing, like ACBr, FastReport, FortesReport, cryptography dlls or tools, etc.

Can you disclose a little bit more?

To give you a tease of what will be presented, here are some screenshots of the API that we will show and explain at the event:

Not only that…

This will be a really interesting session. There will be an additional surprise that for sure will be very interesting for all those who work with Delphi and deal with such legal Brazilian documents. That’s just the beginning… See you at Embarcadero Conference 2019!

Databases inside Delphi Ecosystem: Webinar

On October 10, Softacom is holding a webinar on “Databases inside RAD Studio & Delphi ecosystem. Migration process (legacy to up-to-date, to another RDBMS), data layer architecture (ORM), data access architecture (REST API)”.

Speakers

Wagner Landgraf from landgraf.dev will be one of the speakers, talking about how database access evolved in Delphi since the early versions, Object Relational Mapping (TMS Aurelius), REST API Servers (TMS XData) and remote database access (TMS RemoteDB).

Serge Pilko

Serge Pilko

Embarcadero MVP & CEO of Softacom – Enterprise digital transformation & software modernization services expert

Wagner Landgraf

Wagner Landgraf

CEO of landgraf.dev / TMS Software Partner / TMS Business Product Manager

Bruno Fierens

Bruno Fierens

Embarcadero MVP & CEO of TMS Software – Main player as Delphi and C ++ Builder 3rd party vendor

What will you learn

For CEO / Owner / CTO / IT – Director / Product Manager:

  • Up-to-date Delphi solutions and frameworks for communications with databases;
  • Pitfalls of migration to up-to date or another type of RDBMS;
  • Cutting-edge Delphi-related solutions and practices for RDBMS;
  • Arguments, why you have to use Delphi and RAD Studio for your multi-tier applications;

For Developers and Technical Specialists:

  • Best practices for developing data access layers for RAD Studio projects;
  • How to use ORM for Delphi projects;
  • How to develop REST API server as DB facade;
  • Insights, tips and tricks for the app developers from the first mouth of DB tools and DB framework developers;

Webinar Highlights:

  • Most popular data access patterns 10-15 years ago and today;
  • Pitfalls of migration legacy versions of RDBMS to up-to-date versions;
  • Pros and cons of migration to ORM instead of using regular practices;
  • ORM for Delphi ─ TMS Aurelius from TMS Software. Pros and cons of the solution;
  • Pros and cons of migration to REST API instead of using “classic” DB access;
  • REST API server for Delphi ─ RAD server. Pros and cons.

For webinar attendees only!

Don’t miss a chance to get your discount promo code for EKON conference and 10% discount for new TMS Software licenses.

Registration

Registration link: https://www.softacom.com/en_softacom_october_webinar

5 Reasons to Use Inline Variables in Delphi

Inline variables declaration is a feature introduced in Delphi Rio 10.3. What is it?

In short, it is the possibility to declare a variable in any line of your code. That is, you can declare a variable this way, within the begin..end block:

procedure Test;
begin
  var I: Integer;
  I := 22;
  ShowMessage (I.ToString);
end;

A lot of people already understood how this feature works, but did not understand why it is interesting. In this article, I will show you this new feature with a focus on the advantages it brings.

1. Organizes your code

The variable is only accessible from the point it is declared. For many people this better organizes the code in a large method, because it is possible to know better where that variable is being used. Consider the following code:

procedure Test;
var 
  A, B, C, D, E: Integer;
  Found, Done, Excluded: Boolean;
  Text: string;
begin
   // many
   // lines
   // of
   // code
end;

It may be confusing to know where all of these variables are used, when they are being initialized, if it has been set a value before, etc. In the following code, we know that the Text variable, for example, does not exist at the beginning of the code, and that it is only used at the end. No code changed its value bfore that part of the code:

procedure Test;
begin
   var A, C: Integer;
   // We cannot use Text here
   // lines
   // of
   // code
   
   var Text: string;
   // Text can only be used here
end;

Update (May 18, 2020): Darian Miller provides even more benefits of using inline variables in his nice blog post “Newly discovered hidden benefits of inline variables in Delphi“.

2. Minimizes bugs

Have you ever done something like this:

procedure Test;
var I: Integer;
begin
  for I := 0 to Count - 1 do
    Process;
  DoSomethingWithI(I);
end;

That is, using the for variable after the loop is finished. This is not safe, and although the compiler raises a warning for this, many people ignore it. By declaring the for variable inline, it will be only valid inside the for, and using it outside the block will result in a compilation error:

procedure Test;
begin
  for var I: Integer := 0 to Count - 1 do
    Process;
  DoSomethingWithI(I); // Compile error!!!
end;

The benefit from the code above comes from the fact that the scope of the variable is limited to the block in which they are declared. That minimizes the chance of errors. For example, suppose you have a code like this:

procedure Test;
var I: Integer;
begin
  I := CalculateSomething;
  Persist(I);
  // many lines below...
  Log(I);
end;

Then you eventually need to refactor the code in a way that the first part only executes under a specified condition. You think that variable I is only being used there, and do something like this:

procedure Test;
var I: Integer;
begin
  if Condition then
  begin
    I := CalculateSomething;
    Persist(I);
  end;
  // many lines below...
  Log(I);
end;

There, you forgot the last line and maybe the value of I is not what you expect. Changing the scope of your variable to the block will generate compilation errors if the variable is used outside the block, which will show you the problem immediately, so you can make a decision:

procedure Test;
begin
  if Condition then
  begin
    var I: Integer;
    I := CalculateSomething;
    Persist(I);
  end;
  // many lines below...
  Log(I); // Compile error!
end;

3. Less typing

Who does not want more productivity? If you can type a bit less to declare a variable, why not? You can now declare and initialize a variable at the same time:

procedure Test;
begin
  var I: Integer := 22; 
  ShowMessage (I.ToString);
end;

But not only that. There is also type inference, which means that in most cases you do not need to include the variable type when declaring it. Just initialize the variable with a value and Delphi will know the variable type.

Looks like it’s not a big deal? Imagine a case where the variable type is using heavy generics:

procedure NewTest;
var
  MyDictionary: TObjectDictionary<string, TObjectList<TMyAmazingClass>>;
  Pair: TPair<string, TObjectList<TMyAmazingClass>>;
  List: TObjectList<TMyAmazingClass>;
begin
  MyDictionary := TObjectDictionary<string, TObjectList<TMyAmazingClass>>.Create;
  MyDictionary.Add('one', CreateList);
  Pair := MyDictionary.ExtractPair('one');
  List := Pair.Value;
  ShowMessage(List.Count.ToString);
end;

Using inline variable and type inference, you can rewrite the code this way:

procedure NewTest;
begin
  var MyDictionary := TObjectDictionary<string, TObjectList<TMyAmazingClass>>.Create;
  MyDictionary.Add('one', CreateList);
  var Pair := MyDictionary.ExtractPair('one');
  var List := Pair.Value;
  ShowMessage(List.Count.ToString);
end;

Better, isn’t it?

4. Increases performance

The fact that the variables belong to a more limited scope (within a begin..end block) can even increase code performance!

You can see more details in this excelent article: Inline Variables can increase performance. In summary: the variable will initialized only if the code execution enters the block, and finalized only upon block exit. In this code, for example:

procedure TestInlineVars(const ACondition: Boolean);
begin
  // BEFORE
  if (ACondition) then
  begin
    var S := 'Inline String';
    var I: IInterface := TInterfacedObject.Create;
    var F: TFoo;
    F.S := 'Managed Record';
  end;
  // AFTER
end;

Variables S, I and F are managed types (string, interface and record). The compiler automatically adds initialization and finalization code for them.

If you call TestInlineVars procedure a million times, it will have a big impact. However with the code above, the variables will only be initialized if ACondition is true and the block is actually executed. Less unnecessary code being executed.

5. Makes it easier to use conditional directives

This feature can help even in small things. This article brought my attention: Unexpected Benefit of Inline Variables: Conditional Blocks.

If you use compiler directives where you declare and use different variables for each situation, you have also wrap variable declarations around a compiler directive as well:

procedure DoesSomething;
var
  {$IFDEF CASE1}
  var1: Integer;
  {$ENDIF}
  {$IFDEF CASE2}
  var2: Integer;
  {$ENDIF
begin
  {$IFDEF CASE1}
  // use var1
  {$ENDIF}
  {$IFDEF CASE2}
  // use var2
  {$ENDIF}
end;

Boring, huh? In my opinion this is easier:

procedure DoesSomething;
begin
  {$IFDEF CASE1}
  var1: Integer;
  // use var1
  {$ENDIF}
  {$IFDEF CASE2}
  var2: Integer;
  // use var2
  {$ENDIF}
end;

I believe that inline variables still brings other subtle benefits in specific situations that are not listed here. If you can think of any other benefit, leave your comment. If you do not agree and you think inline variables are not good news for Delphi, leave your comment as well. Just do not forget one thing: if you didn’t like it, simply don’t use it!

What I liked about Delphi/Rad Studio 10.3.2 update

Embarcadero has just released a new Delphi Rio version (which means also Rad Studio and C++ Builder): version 10.3.2. It’s a minor update – meaning product codename is still “Rio”, and it’s binary (DCU) compatible with previous 10.3.1 version.

Why then, an article about a minor update? Usually minor updates contain just bug fixes and small improvements, however it’s not the case of this one. I will mention here two improvements that I personally found significant. It’s also worth mentioning that Embarcadero has recently published the updated Rad Studio roadmap – May 2019 which lists the probable new improvements in upcoming major versions. Now to the improvements in this release:

macOS 64-bit support

Delphi 10.3.2 finally supports macOS 64-bit platform. If you develop macOS applications with Delphi, you know how much this is important.

Apple has been planning moving all macOS applications to 64-bit for years and informing users and developers that 32-bit macOS applications will be deprecated soon. And the time has come. When using macOS Mojave and trying to run 32-bit applications (the ones built with Delphi until 10.3.1, for example), users are receiving the following message:

App is not optimized for your Mac and needs to be updated

I would say that your application wouldn’t give much confidence to the user, do you agree? And, finally, in next macOS release, macOS Catalina (10.15), 32-bit applications will simply not work anymore.

Thus, if you develop (or intend to develop) macOS applications with Delphi, it’s a relief to know that you won’t have those problems anymore: just build 64-bit macOS applications and everything is going to be alright!

IDE stability and performance

Another improvement that is worth mentioning is the significant improvement in IDE stability and performance. First Delphi Rio version brought us a refreshed IDE, with dark theme and more modern visual. But there were also issues: flickering, strange visual “effects”, slowness, the screen was redrawn several times when you resized the window, among other things.

That was significantly improved in this new update. If you are already using previous Delphi Rio 10.3 or 10.3.1, I believe you will notice the difference, with a smoother and snappier IDE in this regard.

Delphi Rio 10.3.2 is already available! There are many other improvements besides the ones mentioned above. If you are already using this new update, leave a comment telling what do you think about it!

What are memory leaks and what are their consequences?

A memory leak happens when your application allocates a space in memory and never frees it again.

How memory leaks happen in Delphi

In a Delphi application, memory spaces are allocated and released all the time. This is often done automatically by the compiler or by the RTL – for example, when allocating variables of primitive types, parameters that are passed to functions, etc. – and we usually do not have to worry about it.

However, there are many cases where we allocate memory manually. Instantiating an object is one of them:

Obj: = TMyObject.Create;

The code above will allocate a memory space and the Obj variable will point to the address of allocated memory space. To release it, you can use the Free method:

Obj.Free;

If the developer forgets to call the Free method, the memory space associated with the object is never released. We have a memory leak.

Consequences of memory leaks

You may wonder: "What’s the problem? I’ve seen this happen in my application and I’ve never had any practical problems!"

Actually, we often don’t see issues when there are just a few memory leaks, and the consequences also depend on the type of applications:

Client applications (desktop or mobile)

In general, in desktop or mobile applications, the consequences are not very serious. In current operating systems, the memory allocated by the application is generally released when the application is terminated, so as not to cause system instability.

Even so, if your application generates a lot of memory leaks, there may be some problems, caused by excessive memory usage:

  • Slow application and/or system: Disk access may be necessary to get around the memory shortage.

  • Application abrupt closing: The operating system may force application termination due to excessive memory usage. This is more common in mobile applications.

  • Application bugs: Application code that allocates memory can start to crash and cause bugs.

Server Applications

When talking about server applications, the problem gets worse. That’s because ideally you will never close the server – you want it to run "forever" without needing to restart it.

The consequences are almost the same as the ones for desktop applications, but since the server application theoretically should never close, any small memory leak will have consequences in the future. The memory will slowly be consumed over days, weeks, months, and your server performance will degrade, bugs will appear and eventually the server will stop working.

Avoiding Memory Leaks

There are techniques and tools to help you detect and remove memory leaks from your application. This will be covered in future posts.

What about you? Have you ever had issues in your application caused by memory leaks? Do you consider detecting and removing memory leaks a low-priority task compared to other more important things to worry about in your code? Leave a comment!