Forum > General
Reusing unit paths across build modes
(1/1)
Чебурашка:
Hi,
it happened to me several times that I have 2/3 Lazarus build modes, and I need to modify the unit paths (-Fu) to include additional stuff.
The problem is that I have to make it manually in each build mode every time, and of course I do mistakes almost always.
Of course it is senseful to have different unit paths depending on the build mode, for example to include extra units related to debugging, but I would like to know if is possible to "import" or "refer to" the unit path of another build mode, so that in case I need modify I can make it in the "principal" build bode, an the modification is reflected automatically in other ones.
n7800:
Unfortunately, Lazarus does not yet support "inheritance" of build modes. But I can offer you alternatives:
1) Use conditional compilation:
https://wiki.freepascal.org/Conditional_compilation
You can define "symbols" for each build mode by clicking on the "Defines..." button in this options section:
https://wiki.freepascal.org/IDE_Window:_Compiler_Options#Custom_Options
This will allow certain parts of the code to only compile in specified build profiles:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TForm1.FormCreate(Sender: TObject);begin {$IFDEF DebugBuild} ShowMessage('This message will only be shown in debug build mode'); {$ENDIF}end;
2) If you want to specify different units in each build mode, then use conditional compilation directly in the "uses" section:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses Classes, SysUtils {$IFDEF DebugBuild}, MyDebugUnit{$ENDIF};
3) Or you can use the following compiler directive:
https://www.freepascal.org/docs-html/prog/progsu119.html
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$IFDEF ReleaseBuild} {$UNITPATH units\release}{$ELSE} {$UNITPATH units\debug}{$ENDIF} uses Classes, SysUtils, MyUnit;
4) The same link (at the end of the page) provides another method via:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses Classes, SysUtils, {$IFDEF ReleaseBuild} MyUnit in 'units\release\MyUnit.pas' {$ELSE} MyUnit in 'units\debug\MyUnit.pas' {$ENDIF} ;
Read the warnings about relative paths carefully.
Navigation
[0] Message Index