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

Comments

  1. 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.

    ReplyDelete
  2. Can you specify what you are trying to achieve? Perhaps there are other approaches.

    ReplyDelete
  3. To me it sounds like he wants to ensure that the code is platform independent.

    I wonder - if he set the platform related warnings to Error in the compiler - that might bring him some of the way?

    ReplyDelete
  4. Uwe Raabe I want to be sure that nobody will use winapi in the project. Lars Fosdal Exactly! :)

    The whole problem is simple. I have fmx app ... now only for Windows. But later, it could be multiplatform. I want to be prepared well... :)

    ReplyDelete
  5. I'd write a script that parses the map file looking for the units/namespaces that you don't want to be included.

    ReplyDelete
  6. Couldn't you simply define invalid alias names within the compiler options?

    ReplyDelete
  7. Oliver Funcke Could you explain me more? Thank you... :)

    ReplyDelete
  8. 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.

    ReplyDelete
  9. Uwe 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).

    ReplyDelete
  10. Oliver Funcke Better for project files only...
    Anyway I must admit that the problem is more complicated than I thought.

    ReplyDelete
  11. I still think my first suggestion is the least complicated and most effective way.

    ReplyDelete

Post a Comment