Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Sharing the same unit between projects (https://www.delphipraxis.net/206326-sharing-same-unit-between-projects.html)

Skullwing 9. Dez 2020 19:19

Sharing the same unit between projects
 
Hi, following question: I want to share the same unit over multiple projects, is there a way to tell him which "uses" he shall use depending on the project? The same way I can tell him which functions to use depending on the operating system?
The problem is, if I include a file which doesn't exist in another project ...

Thanks,
Etienne

Rollo62 10. Dez 2020 11:52

AW: Sharing the same unit between projects
 
The problem with missing include files is very annoying.
You have the possibility to add a define in the IDE global project options, defines section for each project.
E.g.
Global Define: _X_USE_MY_UNITS

Delphi-Quellcode:
{$IF DEFINED( _X_USE_MY_UNITS ) }
{$INCLUDE MyUnit }  //<== declares maybe _X_USE_MY_SPECIAL_UNIT_1, ...
{$ENDIF }

Uses
{$IF DEFINED( _X_USE_MY_SPECIAL_UNIT_1 ) }
    MySpecialUnit1,
{$ENDIF }
{$IF DEFINED( _X_USE_MY_SPECIAL_UNIT_2 ) }
    MySpecialUnit2,
{$ENDIF }
{$IF DEFINED( _X_USE_MY_SPECIAL_UNIT_3 ) }
    MySpecialUnit3,
{$ENDIF }
   ...
{$IF    DEFINED( MY_VARIANT_UNIT_1 ) }
    MyVariantUnit1,
{$ELSEIF DEFINED( MY_VARIANT_UNIT_2 ) }
    MyVariantUnit2,
{$ELSEIF DEFINED( MY_VARIANT_UNIT_3 ) }
    MyVariantUnit3,
{$ENDIF }

    LastUnit
  ;
Would be much nicer, if could be detected if Include file is declared or not.


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:00 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz