Recent

Author Topic: How to create template for a new Project  (Read 1642 times)

BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
How to create template for a new Project
« on: January 29, 2022, 07:51:23 pm »
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

Чебурашка

  • Hero Member
  • *****
  • Posts: 568
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: How to create template for a new Project
« Reply #1 on: November 25, 2022, 02:20:15 pm »
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  [Select][+][-]
  1. program project1;
  2.  
  3. {This in TT's template project}
  4.  
  5. begin
  6.   {Initialization}
  7.   // ...
  8.  
  9.   {Startup}
  10.   // ...
  11.  
  12.   {Master cycle}
  13.   // ...
  14.  
  15.   {Finalization}
  16.   // ...
  17. end.
  18.  

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  [Select][+][-]
  1. touch project.ini
  2.  

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  [Select][+][-]
  1. [Project]
  2. Name=Example of Template
  3. Author=SomePerson
  4.  
  5. [Variables]
  6. MaxNumberOfNetConn=Maximum network connections allowed (integer number 0=no connection, 1-4)
  7. Dimensions=Integer 1-3
  8.  

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  [Select][+][-]
  1. program project1;
  2.  
  3. {This in TT's template project}
  4.  
  5. const
  6.   MaxNumberOfNetConn = __MaxNumberOfNetConn__;  
  7.   Dimensions = __Dimensions__;
  8.  
  9. begin
  10.   {Initialization}
  11.   // ...
  12.  
  13.   {Startup}
  14.   // ...
  15.  
  16.   {Master cycle}
  17.   // ...
  18.  
  19.   {Finalization}
  20.   // ...
  21. end.
  22.  

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).



« Last Edit: November 25, 2022, 02:22:07 pm by tt »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

ASerge

  • Hero Member
  • *****
  • Posts: 2241
Re: How to create template for a new Project
« Reply #2 on: November 25, 2022, 03:23:14 pm »
Put some values and do ok.
А 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.

Чебурашка

  • Hero Member
  • *****
  • Posts: 568
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: How to create template for a new Project
« Reply #3 on: November 25, 2022, 03:59:42 pm »
Put some values and do ok.
А 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.

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

Code: Pascal  [Select][+][-]
  1. [Project]
  2. Name=Example of Template
  3. Author=SomePerson
  4.  
  5. [Variables]
  6. MaxNumberOfNetConn=Maximum network connections allowed (integer number 0=no connection, 1-4)|2
  7. Dimensions=Integer 1-3|3
  8.  
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: How to create template for a new Project
« Reply #4 on: November 25, 2022, 05:33:27 pm »
But I doesn't work, or I doing some thing wrong.

/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
« Last Edit: November 25, 2022, 06:56:14 pm by MarkMLl »
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

ASerge

  • Hero Member
  • *****
  • Posts: 2241
Re: How to create template for a new Project
« Reply #5 on: November 26, 2022, 02:11:08 am »
Sorry defaults are forseen
I meant the default values for the input fields in the dialog box to immediately click OK, not for additional variables.

Чебурашка

  • Hero Member
  • *****
  • Posts: 568
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: How to create template for a new Project
« Reply #6 on: November 28, 2022, 09:19:56 am »
Sorry defaults are forseen
I meant the default values for the input fields in the dialog box to immediately click OK, not for additional variables.

The only default values allowed at the moment are the ones related to the variables section.
Project name and path are a necessary, but this does not seem strange to me, as we are dealing with a template for a project. I would agree with you if the topic was about templating of components, like for example forms or simple classes, that one might want to add on and existing project, and later save on the filesystem after some further coding work.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

 

TinyPortal © 2005-2018