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 later).

One thing that makes the command line app life easier is the encapsulation of the switches in a record (Current Delphi versions allow records with methods).

This record can be used directly in the .dpr file.

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

4 Responses to Switches

  1. Ryan Mills says:

    Why would you use a record for this type of functionality instead of an object or component? Is this a personal preference or is there another advantage that I’m having trouble seeing?

  2. roman says:

    A component has the disadvantage that I always have to create and destroy an instance.

    An object with class methods is an alternative but it also produces an overhead in space.
    As long as I don’t need inheritance I prefer records. The unit System.IOUtils has some nice examples for this strategy.

    • Ryan Mills says:

      Ok, that makes sense. I’ll take a look at System.IOUtils, thanks.

      What would you do to add persistance to your record? I have taken your idea and expanded it a little to make it more, in my mind, functional.

      I’ll post another comment tonight and provide my current WIP based on your post. I’d like to hear your thoughts on what I’ve done vs. your code.

  3. roman says:

    If you need persistence I think you should work with an instance. A record can have properties in the same way as an object. But if you would like to work with further technologies like streaming you should work with objects. Maybe you should have a look at the post about records.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.