How Delphi Compiles my code
How will the Delphi compiler compiles the following code ;
uses a_big_unit; procedure TForm1.Button1Click(Sender: TObject); var acompont : T_a_big_component ; begin if (true = false ) then // or if false then begin bc := Tbig_component.create(self) end;
in this code true = false will never happen so component acompont will never created .
when delphi is compiling in optimized mode will these unused units and code are omitted
AND WHEN using units
in delphi 7 , even if you just uses XPMan unit; (without using any components it has(TXPManifest1)) , still the unit is used and every components are shown with theme ;
and some said Delphi will omit units if it is not needed ;
So how Delphi identifies whether a unit has an impact on the unit it calls or not
See for yourself: Compile the code and run it in the debugger. You won't be able to set a breakpoint on any statements inside the if false then block, and you won't be able to set any breakpoints in the constructor of the Tbig_component class in the other unit. Why? Because there isn't any code for these statements.
You can also view the machine code generated by the compiler by opening the Disassembly view in the IDE. It will show the machine code for each source line. You'll find there will be no machine code generated for the if false then block.