Nice Approach For Exception Safe Code

Maybe everyone knows the issue with code that is not exception safe. Let’s see an example:

The function MyFunction returns an instance of an object which is normally no problem. But MyFunction creates the instance and then runs further code. And in case of an exception no one “cares” about the instance and you will simply get a memory leak.

That’s why people normally avoid functions that return instances or write the code in an exception safe way:

At this point some purists would say that the Result should also be assigned to nil after it had been destroyed.

I don’t want to start a long discussion about FreeAndNil but what people, including myself, don’t like is to catch an exception in order to raise it again a moment later.

Instead the code could be written with a try-finally-block:

The tricks are:

  1. Free can be called if an instance is nil.
  2. Finally is always called.
  3. After assigning the Result no further code that could cause an exception is called.
Posted in Delphi, FireMonkey, RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, RAD Studio XE5, RAD Studio XE6, RAD Studio XE7, RAD Studio XE8, Tips and Tricks | 7 Comments

PNG Components and Tokyo

This week I received an email from Uwe Raabe that he has updated his png components under bitbucket.

That’s why I just updated the TurboPack version under GitHub.

As I mentioned in a previous post the RAD Studio 10.2 Tokyo version of TurboPack of is now located at a different place.

I will also ask Marco to update GetIt.

Posted in C++-Builder, Delphi, RAD Studio 10.2 Tokyo, Third Party Components, TurboPack, TurboPower | 2 Comments

TFile.Size 2.0

Yesterday I got a suggestion for a better implementation for TFile.Size from Stefan Glienke. Many thanks for it, Stefan.

In order to make the code compatible to other functions in System.IOUtils, I modified it in the way that I’m raising an EInOutError if there is a problem.

I could compile the code for all platforms Win32, Win64, MacOS32, iOS32, iOS64, Android32 and Linux64.

Posted in C++-Builder, Delphi, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, Uncategorized | Leave a comment

TFile.Size

I use very often the System.IOUtils units with the wonderful classes/records TPath, TDirectory and TFile. They are much more comfortable than the old functions from System.SysUtils like FindFirst etc..

But there is one method I’m really missing: It is the size of a file. For sure there are some workarounds but I think that this method belongs to TFile. That’s why I wrote a small helper class:

I will try to convince Marco or Jim to add this method to the next release. So stay tuned.

Posted in C++-Builder, Delphi, RAD Studio 10.2 Tokyo, Uncategorized | 6 Comments

RAD Studio 10.2 Tokyo and TurboPack

Maybe most of you already heard that the next release of RAD Studio will be 10.2 Tokyo. Additionally to supporting Win32, Win64, MacOS, iOS and Android RAD Studio 10.2 Tokyo will support Linux64.

As always  I updated the TurboPack libraries and made them available via GetIt and hosted them under GitHub.

But this time we changed the location to a Tokyo-specific one. The reason is that it is easier to find the fitting version for your version of RAD Studio.

For RAD Studio 10.2 Tokyo I updated the suffix of the packages from ‘240’ to ‘250’. The ‘240’ 10.1 Berlin versions for RAD Studio XE are still available under GitHub.

The libraries compile for Delphi and C++Builder.

Maybe the most important change is that compression toolkit Abbrevia also works for Linux64.

Currently they libraries are:

  1. Abbrevia
  2. AsyncPro
  3. DOS command
  4. Essentials
  5. LockBox
  6. LockBox 3
  7. OnGuard FMX
  8. OnGuard VCL
  9. Orpheus
  10. PNG components
  11. PowerPDF
  12. SynEdit
  13. SysTools
  14. VirtualTreeView
Posted in C++-Builder, Delphi, FireMonkey, RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio 10.2 Tokyo, RAD Studio XE5, RAD Studio XE6, RAD Studio XE7, RAD Studio XE8, SourceForge, Third Party Components, Tips and Tricks, TurboPack, TurboPower | Leave a comment

IMAPSize

From time to time I’m making backups from my IMAP account. Therefore I’m using a small tool called IMAPSize.

IMAPSize is written in Delphi 5 and the code is hosted under sourceforge.

Last week it has been impossible to connect to my IMAP account with IMAPSize that’s why I wanted to debug it.

Since I didn’t want to reinstall Delphi 5 I converted the code to Delphi Berlin and published it under bitbucket.

I had to get rid of some very old Third Party VCL components and replaced them with the VCL standard controls so that the Delphi Berlin version currently isn’t as smooth as the original one. But with some additional hours of time things could be fixed.

Anyway, I could debug the tool and found out what the problem was: IMAPSize uses the Synapse components to connect to an IMAP server which themselves use OpenSSL. Therefore IMAPSize ships two dlls which were simply outdated.

Now I’m considering to move IMAPSize to FireMonkey and additionally to a console application. With these changes IMAPSize would run on the Mac and maybe in the future on Linux but I therefore I would need some sponsors. So any help or thoughts are appreciated.

Posted in Delphi, RAD Studio 10.1 Berlin, SourceForge, Third Party Components, Tips and Tricks, TurboPack | 5 Comments

EncodeString

This week I had to migrate an application from Delphi XE3 to Delphi Berlin and this application uses a Base64 encoding.

Normally Base64 encoding is not difficult stuff and Delphi XE3 simply offers the function EncodeString in the unit Soap.EncdDecd.

Since Delphi Berlin has the same function I thought that I didn’t have to change a single line of code. But the first thing I realized is that the function is nearly deprecated. This means that it already has a deprecated comment: // deprecated ‘Use TNetEncoding.Base64.Encode’.

Such a comment means that the function will become deprecated with one of the next Delphi releases.

A short look at the implementation shows the reason:

I should call TNetEncoding.Base64.Encode directly instead of using the old function EncodeString.

But then I realized that the two Delphi versions show different results.

Let’s have a look at a small example with some German umlauts:

Delphi XE3 shows ‘xOTW9tz83w==’ whereas Delphi Berlin shows ‘w4TDpMOWw7bDnMO8w58=’.

So bad luck, I had to have a deeper look at the code. Let’s start with Delphi XE3:

This means that the string is first converted into bytes with the help of the default encoding which is under Windows an ANSI encoding. After that the bytes are encoded.

Let’s have a look at the Delphi Berlin implementation:

Delphi Berlin always converts the string into UTF-8 bytes and then encodes the bytes. This means that the implementation of EncodeString in Delphi Berlin differs to the implementation in XE3.

To fix this issue let’s try the following implementation in Delphi Berlin:

I first convert the string into bytes with the help of the default encoding. Then I encode the bytes with the new Base64 class and at the end I have to convert the bytes back to a string.

I will contact Embarcadero/Idera and ask them if I should write a quality portal case.

Posted in C++-Builder, Delphi, FireMonkey, RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio XE5, RAD Studio XE6, RAD Studio XE7, RAD Studio XE8, Tips and Tricks, Uncategorized | 4 Comments

GitHub or Bitbucket

I’m currently hosting the TurboPack components under GitHub but which not surprisingly supports Git. But normally I’m working with HG because of the great TortoiseHG tool.

With the the help of the HGGit extension I can use TortoiseHG with Git bit it doesn’t work smoothly. That’s why I’m considering to move all libraries to Bitbucket and HG.

Does anyone have any objections or reasons why I shouldn’t do so?

Posted in C++-Builder, Delphi, FireMonkey, RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio XE5, RAD Studio XE6, RAD Studio XE7, RAD Studio XE8, SourceForge, Third Party Components, Tips and Tricks, TurboPack, TurboPower, Uncategorized | 7 Comments

RAD Studio 10.1 Berlin and TurboPack

Maybe most of you already heard the latest news, today RAD Studio 10.1 Berlin shipped. With the release of the version of RAD Studio I updated the TurboPack libraries. You can download the TurboPack libraries manually from the TurboPack website or you can use the GetIt tool from RAD Studio.

For RAD Studio 10.1 I updated the suffix of the packages from ‘230’ to ‘240’. The ‘230’ 10.0 Seattle versions for RAD Studio XE are still available under GitHub.

The current libraries are:

  1. Abbrevia
  2. AsyncPro
  3. DOS command
  4. Essentials
  5. LockBox
  6. LockBox 3
  7. OnGuard FMX
  8. OnGuard VCL
  9. Orpheus
  10. PNG components
  11. PowerPDF
  12. SynEdit
  13. SysTools
  14. VirtualTreeView
Posted in C++-Builder, Delphi, FireMonkey, RAD Studio 10 Seattle, RAD Studio 10.1 Berlin, RAD Studio XE5, RAD Studio XE6, RAD Studio XE7, RAD Studio XE8, SourceForge, Third Party Components, Tips and Tricks, TurboPack, TurboPower, Uncategorized | 45 Comments

ConTEXT Editor 2nd

Today I published the ConTEXT editor.

As I explained in my previous post ConTEXT is a small, fast and powerful freeware text editor, developed to serve as a secondary tool for software developers.

It has originally been hosted here. During the last weeks I tried to contact the original developers and even Marco Cantu from Embarcadero tried to contact someone from the original team but without success.

That’s why I published the source code under bitbucket. The code can be compiled with Delphi 10 Seattle. I also added the Win32 and Win64 binaries. For the German language I uploaded a language file.

If someone is interested it would be terrific to add further languages.

Posted in Delphi, RAD Studio 10 Seattle, RAD Studio XE6, Third Party Components, TurboPack, Uncategorized | Leave a comment