Is there a conditional define for library projects in Delphi?

前端 未结 2 1372
耶瑟儿~
耶瑟儿~ 2021-01-23 04:57

I have a utility unit with code shared between a few applications and DLLs. I\'d like to selectively compile portions of this unit based upon the current project type: Applicati

2条回答
  •  没有蜡笔的小新
    2021-01-23 05:28

    IMHO there is absolutly no need for such conditionals because of existing conventions.

    Compiling an Application or Library (the same on this compiling aspect) or a Package differs like so:

    • Application/Library will compile only the used parts from the unit
    • Package will compile all parts from the unit referenced by the interface part of the unit

    Example Unit

    unit foo;
    
    interface
    
    procedure foo1;
    procedure foo2;
    
    implementation
    
    procedure foo3; 
    begin
      // used by foo2, compile depends on foo2 compilation
    end;
    
    procedure foo4;
    begin
      // will never be compiled, because is never used
    end;
    
    procedure foo1;
    begin
      // Package: will always be compiled
      // Application/Library: will be compiled if used 
    end;
    
    procedure foo2;
    begin
      // Package: will always be compiled
      // Application/Library: will be compiled if used 
    
      foo3;
    
    end;
    
    end.
    

    That is also a reason, why using packages may result in bigger exe files, because it can contain unused code parts from precompiled dcu files.

提交回复
热议问题