delphilinkerdelphi-7

Compile/Link unused Functions/Procedures in Delphi


I would like to "provide" several functions/procedures or even vars in my application without ever using them in my own code. Does the compiler automatically ignore unused vars and functions or is it the linker? How can I change that? I already tried to uncheck CodeGeneration ---> Optimization but with no luck.


Solution

  • If something in your program refers to the object then the linker cannot remove it. So you can take advantage of this like this:

    procedure StopLinkerRemoval(P: Pointer);
    begin
    end;
    

    Then in your initialization section you can write this:

    StopLinkerRemoval(@MyVar);
    StopLinkerRemoval(@MyFunction);
    

    All you need to do is refer to the object. You don't need to call the function, or read/write the variable, just take its address.