Hi, I just wonder. Is it possible to forbid use of some namespace? I need to disallow usage of WinApi everywhere in the project. Then explicitely define one unit where it's possible. I'm using XE7...
I can't think of a way that effectively will forbid it, as long as you are working on the Windows version of a project.
If you use a continuous integration platform like Continua, you can enforce it with requiring that a non-windows platform project must successfully build before you build your Windows project.
Oliver Funcke That is not working! If you alias f.i. WinApi.Windows to an invalid unit name (say NoWinApi.Windows) then simply using System.Sysutils will throw an error as it uses WinApi.Windows.
I can't think of a way that effectively will forbid it, as long as you are working on the Windows version of a project.
ReplyDeleteIf you use a continuous integration platform like Continua, you can enforce it with requiring that a non-windows platform project must successfully build before you build your Windows project.
Can you specify what you are trying to achieve? Perhaps there are other approaches.
ReplyDeleteTo me it sounds like he wants to ensure that the code is platform independent.
ReplyDeleteI wonder - if he set the platform related warnings to Error in the compiler - that might bring him some of the way?
Uwe Raabe I want to be sure that nobody will use winapi in the project. Lars Fosdal Exactly! :)
ReplyDeleteThe whole problem is simple. I have fmx app ... now only for Windows. But later, it could be multiplatform. I want to be prepared well... :)
I'd write a script that parses the map file looking for the units/namespaces that you don't want to be included.
ReplyDeleteCouldn't you simply define invalid alias names within the compiler options?
ReplyDeleteOliver Funcke Could you explain me more? Thank you... :)
ReplyDeleteOliver Funcke That is not working! If you alias f.i. WinApi.Windows to an invalid unit name (say NoWinApi.Windows) then simply using System.Sysutils will throw an error as it uses WinApi.Windows.
ReplyDeleteUwe Raabe that's right. OP asked for "disallow usage of WinApi everywhere". Milan Kormout see http://docwiki.embarcadero.com/RADStudio/XE7/en/Delphi_Compiler (unit aliases).
ReplyDeleteOliver Funcke Better for project files only...
ReplyDeleteAnyway I must admit that the problem is more complicated than I thought.
I still think my first suggestion is the least complicated and most effective way.
ReplyDelete