I then tried using the TSelectDirectory object. This has an option - ofNoChangeDir which, in the notes simply says "Do not change the current directory". I tried setting this but it didn't prevent me from entering sub-directories.
Correct, because that is not what it's meant for.
Have I misinterpreted the action of this option or is there a problem with it?
You have misinterpreted it, but that's understandable because it is documented poorly.
When the user accepts the dialog, by default it changes the calling process's Current Working Directory to be the selected directory. The
ofNoChangeDir option prevents it from doing that.
More accurately, the dialog actively manipulates the CWD while the user is navigating, and the
ofNoChangeDir option simply restores the original CWD when the dialog is closed.
To accomplish what you want, you can use the
TSelectDirectoryDialog.OnCanClose event to prevent the user from accepting an unacceptable folder when closing the dialog. It can't stop the user from navigating to such folders inside the dialog - that takes more work. You can use the
TSelectDirectoryDialog.OnFolderChange and
TSelectDirectoryDialog.OnSelection events to enable/disable the dialog's OK button, based on which folder the user selects/enters.
TBH: ofNoChangeDir in a dialog to selct a directory makes no sense at all to me.
It makes perfect sense, once you understand what it's actually doing.
I would guess ... that setting FOS_PICKFOLDERS (which makes the dialog a TSelectDirectoryDialog) disables FOS_NOCHANGEDIR.
No, it does not. Those options are not mutually exclusive. A
FOS_PICKFOLDERS dialog still manipulates the CWD while active, and
FOS_NOCHANGEDIR restores the original CWD when the dialog is closed.