a year a go i was trying to do something as this question shows How do I use enum values when their type is defined indirectly in another unit? and i was encourage from other users to leave this mentality couse it was not a good approach for various reason.
well, a few days back i was doing some custom dialog for our software and i thought to use some of the types provided nativelly by delphi instead of declared my owns. my surprise was that the file vcl.dialogs
has the same technique i was encourage not to do as the code shows:
{ Message dialog }
mtWarning = System.UITypes.TMsgDlgType.mtWarning;
mtError = System.UITypes.TMsgDlgType.mtError;
mtInformation = System.UITypes.TMsgDlgType.mtInformation;
mtConfirmation = System.UITypes.TMsgDlgType.mtConfirmation;
mtCustom = System.UITypes.TMsgDlgType.mtCustom;
mbYes = System.UITypes.TMsgDlgBtn.mbYes;
mbNo = System.UITypes.TMsgDlgBtn.mbNo;
mbOK = System.UITypes.TMsgDlgBtn.mbOK;
mbCancel = System.UITypes.TMsgDlgBtn.mbCancel;
mbAbort = System.UITypes.TMsgDlgBtn.mbAbort;
mbRetry = System.UITypes.TMsgDlgBtn.mbRetry;
mbIgnore = System.UITypes.TMsgDlgBtn.mbIgnore;
mbAll = System.UITypes.TMsgDlgBtn.mbAll;
mbNoToAll = System.UITypes.TMsgDlgBtn.mbNoToAll;
mbYesToAll = System.UITypes.TMsgDlgBtn.mbYesToAll;
mbHelp = System.UITypes.TMsgDlgBtn.mbHelp;
mbClose = System.UITypes.TMsgDlgBtn.mbClose;
so basically delphi does a buch of replication of this types that are originally declared on System.UITypes
to the vcl.dialogs
file.
so the question is: there's a logical explanation to why he does this? is delphi bad writed? this approach is not that bad? if neither there's a adequate way to use this?
These are not type aliases. These are actually constants. What's more these are true constants rather than typed constants. This means that you can import either Vcl.Dialogs
or System.UITypes
and use mtWarning
.
Embarcadero have done this to allow cross-platform use of this type, and yet maintain backwards compatibility with existing code. The cross-platform need arose when FireMonkey was introduced.
There was a need to use this type in platforms other than Windows. However, the VCL is Windows only. So having the type declared in a VCL namespace unit does not work. Hence the introduction of System.UITypes
. In order to allow existing code to continue compiling, the designers elected to export the same values from Vcl.Dialogs
.
New code should use System.UITypes
to gain access to this enumerated type.