Search code examples
delphibuilddelphi-11-alexandriadelphi-units

Having own library units in the same build config as the project


How can I setup Delphi library folders so I can have both Debug and Release versions of my units library when I work on a project ? Until now I compiled my library in Release mode once is finished. But I encountered situations when I work on a project and I need to follow the debugging steps even in the compiled units. But if they are compiled as Release, it won't let me. And if I compile them as Debug, it puts the debuging code in the Release version of the project, which is not normal. I would like that when I switch between Debug and Release in my project, the units also switch. Can it be done ? If I put both Debug and Releas folders in Delphi library path, it will know when to choose te right one ?


Solution

  • I finally managed to understand how it works: the key is $(Platform) and $(Config).

    I made a test unit with a function that tells me what configuration I'm using:

    unit Test;
    
    interface
    
    function GetConfig: String;
    
    implementation
    
    function GetConfig: String;
    begin
     {$IFDEF RELEASE} Result:= 'Release'; {$ENDIF}
     {$IFDEF DEBUG} Result:= 'Debug'; {$ENDIF}
    end;
    
    end.
    

    I compiled it in Debug and Release mode and saved .dcu files in D:\Delphi\MyLIB\Win32 \Release and \Debug. And the .pas in the D:\Delphi\MySRC. Then I go to Tools > Options > Language > Delphi > Library and I added D:\Delphi\MyLIB\$(Platform)\$(Config) to Library Path section and 'D:\Delphy\MySRC' to Browsing Path.

    Now, if I make a new project and use that unit, the correct version is selected according to Buid Configuration. And if I switch to Debug and do a Trace Into (F7) over that function, I can debug inside it.

    unit Unit1;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Test;
    
    type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.dfm}
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
     Caption:= GetConfig;
    end;
    
    end.
    

    Thanks to Oleksandr Morozevych comment !