Quantcast
Channel: Planet Object Pascal
Viewing all articles
Browse latest Browse all 1725

TPersistent: How to Avoid Getting Upset with OptSets

$
0
0

OptSets are a great thing for using consistent settings across multiple projects and machines (such as a build machine). Although they were introduced in D2009, I have found that there are still issues using them in XE4 which I believe are problems in the software and not my wetware.

The first issue is the DPROJ. Settings are present in the DPROJ that when checked in can have adverse effects on the build machine and other developers unless the same setting is present in the OPTSET (such as compiler related ones). This means you have to make sure when editing the OPTSET that the desired changes are in fact being saved, and understand the difference between Applying an OPTSET and adding a Reference to it.

Some of the settings in the DPROJ should be local IMO (the selection of the build config for instance, or run parameters), but they’re not, so I would recommend not checking in the DPROJ unless you have to. At a minimum, you might want to check in one version, and enable VCS-ignore, only updating the DPROJ under version control when absolutely necessary. This can cause issues with GIT when trying to switch branches, so it’s not ideal, but it has the added advantage that Delphi won’t screw up the DPR file when adding units.

If you utilize Search paths in the OPTSET files, you don’t have to add more than the core application classes to your Delphi project. Error Insight will produce more false positives, but in my experience most developers ignore it anyway or disable it. Other side effects might include the IDE refactoring support, but I find that most refactorings don’t work reliably enough, or across units so I rely on manual refactoring as recommended by Michael Feathers from Object Mentor.

OPTSET files are a subset of MSBuild XML including BuildEvents. Unfortunately, these just don’t work as indicated here.  It’s only been 3 releases, so give it time!

For the most part, OPTSET files work, but beware, editing them in the IDE can produce results other than what you might expect. This may be PEBKAC, but for that reason I use NotePad++, or another external editor, but beware that you will have to close and re-start the IDE for any changes to take effect. Likewise, if you switch between GIT branches with other versions of the OPTSET files, you should re-start the IDE to be sure the correct settings are in use.

It would be nice to have OPTSETS that work as you would expect 100% of the time, but the existing implementation is usable if you understand the limits, and while I am sure this article doesn’t cover all of them, I hope it alleviates some grief.


Viewing all articles
Browse latest Browse all 1725

Trending Articles