I guess that everyone already had to solve this small issue. There are two variables, one with a path, the other with the filename and they have to be combined.
In the old Delphi world there is the function IncludeTrailingPathDelimiter from System.SysUtils.

With the unit System.IOUtils Delphi offers the new record TPath with the method combine.

In our example both functions do the same. But if you look at the implementation of TPath.Combine you can see that it offers some other functionalities. TPath.Combine calls TPath.DoCombine that checks the valid chars and also checks if Path2 is already absolute. This means that the following code raises an exception.

And this code does work.

This entry was posted in Tips and Tricks and tagged . Bookmark the permalink.