Forum > General

How to create template for a new Project

(1/2) > >>

BlueIcaro:
Hello, I installed Lazarus 2.30 using FpcupDeluxe for programing my Raspberry Pi Pico. Every goes nice.
But I would like make a new template. I read this in the wiki https://wiki.lazarus.freepascal.org/Project_Templates
But I doesn't work, or I doing some thing wrong.

Project templates options is pointing to the folder where I have the file.

I attach the files.

Any Idea want I doing wrong?
Thanks
/BlueIcaro

tt:
Hello,
I came across this while playing with new customized templates also. I share my experience on Lazarus 2.0.10/deb 11.5.

Start doing menu Tools/Project templates options... -> then enter the directory where you want all yor templates are stored. In my case was preset to "/home/user_tt/.lazarus/templates".

The goal now is to create a templated called Template001.

Then do File/New.../Simple Program.

Edit the program source file in order to customize it, as this will be part of your template, for example I did:


--- 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";}};} ---program project1; {This in TT's template project} begin  {Initialization}  // ...   {Startup}  // ...   {Master cycle}  // ...   {Finalization}  // ...end. 
Now save the Lazarus project (*.lpi) doing menu Project/Save and make sure file is saved in a subdirectory Template001 of the templates directory. In my case "/home/user_tt/.lazarus/templates/Template001". Choose as file name __ProjName__.lpi (this will automatically update the lpr file name to __ProjName__.lpr and also it will change program name to "program __ProjName__;".

Now open a terminal, go in templates/Template001 directory and do


--- Code: Text  [+][-]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";}};} ---touch project.ini 
Leaving file just empty.


Close and restart lazarus, now you should see in menu File and new item "New project from template > <your path to templates/Template001>".

If you click on it the popup in picture Capture appears (maybe you could try different project name and destination directory. Press Ok and you should be done with your new project from template.

Refinements:

Open the project.ini previously created with a text editor and write:


--- Code: INI  [+][-]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";}};} ---[Project]Name=Example of TemplateAuthor=SomePerson [Variables]MaxNumberOfNetConn=Maximum network connections allowed (integer number 0=no connection, 1-4)Dimensions=Integer 1-3 
Close and restart lazarus, now you should see in menu File and new item "New project from template > Example of Template".

Open the __ProjName.lpr in template folder and modify like this:


--- 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";}};} ---program project1; {This in TT's template project} const  MaxNumberOfNetConn = __MaxNumberOfNetConn__;    Dimensions = __Dimensions__; begin  {Initialization}  // ...   {Startup}  // ...   {Master cycle}  // ...   {Finalization}  // ...end. 
Save it.

Close lazarus and restart.

Do File/New project from template > Example of template, you should see that 2 new items appear below, like in picture Capture2 below. Put some values and do ok.

You will see that these values get substituted in the "template variables" present in your source file(s).



ASerge:

--- Quote from: tt on November 25, 2022, 02:20:15 pm ---Put some values and do ok.

--- End quote ---
А significant disadvantage of this method is the need to enter something before a new project opens. Especially the path to the project. And no "default" values.

tt:

--- Quote from: ASerge on November 25, 2022, 03:23:14 pm ---
--- Quote from: tt on November 25, 2022, 02:20:15 pm ---Put some values and do ok.

--- End quote ---
А significant disadvantage of this method is the need to enter something before a new project opens. Especially the path to the project. And no "default" values.

--- End quote ---

Sorry defaults are forseen, but I did not set them:


--- 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";}};} ---[Project]Name=Example of TemplateAuthor=SomePerson [Variables]MaxNumberOfNetConn=Maximum network connections allowed (integer number 0=no connection, 1-4)|2Dimensions=Integer 1-3|3 

MarkMLl:

--- Quote from: BlueIcaro on January 29, 2022, 07:51:23 pm ---But I doesn't work, or I doing some thing wrong.

--- End quote ---

/What/ doesn't work? I've been through this and have a vague recollection of changing a few things, discussed in an earlier thread.

Edited later to add:

https://forum.lazarus.freepascal.org/index.php/topic,59458.0.html

MarkMLl

Navigation

[0] Message Index

[#] Next page

Go to full version