Monthly Archives: October 2012

ObjGuard

Sometimes it happens that I would like to convert a Delphi object to an interfaces. Interfaces offer some advantages. On the one hand you can handle different objects that are not derived from a common hierarchy but share the same … Continue reading

Posted in Tips and Tricks | Tagged | 1 Comment

More About Records

Since records offer methods and properties they are often used to replace objects. This is possible if there is no need to use inheritance. But there is a significant difference between both. References to objects are like pointers to a … Continue reading

Posted in Tips and Tricks | Tagged | Leave a comment

TPath.Combine

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 … Continue reading

Posted in Tips and Tricks | Tagged | Leave a comment

StringOfChar

This week I found a new interesting piece of code. Someone wanted to initialize a string with a special length of the same char.

Come on guys, this is complete rubbish! In short words, a string is a record … Continue reading

Posted in Tips and Tricks | Tagged | Leave a comment

(Ab)use of Try..Except

Today I found an example of the abuse of a try.. except block.

The idea is simple. StrToInt converts a string to an integer as long as the string contains an integer value. If not an exception will be … Continue reading

Posted in Tips and Tricks | Tagged | Leave a comment

Records

Because of my post about the Switches I would like to mention some things about records. Records are are nice way to do things in an object-oriented way without the overhead of real objects. In the unit System.IOUtils you can … Continue reading

Posted in Tips and Tricks | Tagged | Leave a comment

Naming of Constants

Normally constants improve the readability and maintainability of your code. One example is the minimum value of a single. You can find it in the unit System.Math:

Instead of writing the float value it is easier and more readable … Continue reading

Posted in Tips and Tricks | Tagged | Leave a comment

Switches

During the last weeks it happened often that I had to write some command line apps. The reason for this is that more and more things are running automatically in tools like FinalBuilder (I will write an article about this … Continue reading

Posted in Tips and Tricks | Tagged | 4 Comments

try…finally for multiple objects

Today I found another common mistake. Someone used more than one object and has to free them.

Instead of nested try…finally blocks it is easier and more readable to do the same with one try…finally block

This solution … Continue reading

Posted in Tips and Tricks | Tagged | Leave a comment

ANSIToOEM

Today I found some old source code. Someone wanted to write a file in the old OEM codepage. Therefore he wrote a small function that encapsulates the Windows API CharToOem function.

After that he added the OEM string to … Continue reading

Posted in Tips and Tricks | Tagged | Leave a comment