Recent

Author Topic: Problem creating a Template for a Form  (Read 706 times)

Dzandaa

  • Jr. Member
  • **
  • Posts: 89
  • From C# to Lazarus
Problem creating a Template for a Form
« on: November 26, 2022, 02:53:39 pm »
Hi everybody,

Using Lazarus version 2.0.12 FPC 3.2.0 on Windows

I create a template for a Form following the tutorial https://wiki.lazarus.freepascal.org/Project_Templates

Everything looks fine except in the .lpi where all instance of "Project" are replaced with "MyTest" (The name of my new program)

Example:

Code: Pascal  [Select][+][-]
  1. <ProjectOptions> -> <MyTestOptions>
  2.  
  3. <SessionStorage Value="InProjectDir"/> ->       <SessionStorage Value="InMyTestDir"/>

If I change it "by hand" the project is working.

The files in: template\MyForm



project.ini
__MAINUNIT__.lfm
__MAINUNIT__.pas
__PROJNAME__.ico
__PROJNAME__.lpi
__PROJNAME__.lpr
__PROJNAME__.lps
__PROJNAME__.res


The resulting Files:


MyTest.ico
MyTest.lpi
MyTest.lpr
MyTest.lps
MyTest.res
MyTestU.lfm
MyTestU.pas



project.ini:

Code: Pascal  [Select][+][-]
  1.  [Variables]
  2.  MAINUNIT=Filename for the default unit.pas file
  3.  MAINFORM=Form name
  4.  
  5.  [Project]
  6.  Name=My Custom Form
  7.  Author=Dzandaa
  8.  Description=Lazarus LCL form specifically for my needs
  9.  


Any Idea?

Thank you.

Dzandaa

jamie

  • Hero Member
  • *****
  • Posts: 5045
Re: Problem creating a Template for a Form
« Reply #1 on: November 26, 2022, 09:14:39 pm »
Trying to figure your problem and what I get is you created a Template with a currently active project that you have already did a SaveAs and gave it a new name?

  So, I assume you are talking about the template taking on the name of your current project that you renamed at some point different than Project.

  I guess if you are into making templates wouldn't it be prudent to simply use a default name of a project so the template can take on the same name?

 I mean, the template is only used to start a new app and move on from there, you can then rename that project to something meaningful which shouldn't affect the template from there on.

  I suppose there could be an option to ask for a name when saving the template, who knows.
 
  Why not submit to the laz bug site as a suggestion as a feature?
The only true wisdom is knowing you know nothing

ASerge

  • Hero Member
  • *****
  • Posts: 2049
Re: Problem creating a Template for a Form
« Reply #2 on: November 26, 2022, 11:06:56 pm »
Maybe I misunderstood the question, but inside *.lpi in the template you need to enter __PROJNAME__ instead of the project name.
And this is documented in the "File content" section.

Dzandaa

  • Jr. Member
  • **
  • Posts: 89
  • From C# to Lazarus
Re: Problem creating a Template for a Form
« Reply #3 on: November 27, 2022, 12:00:31 pm »
Hi again,

Thank you.

Here is my __PROJNAME__.lpi

Code: XML  [Select][+][-]
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <CONFIG>
  3.   <ProjectOptions>
  4.     <Version Value="11"/>
  5.     <PathDelim Value="\"/>
  6.     <General>
  7.       <SessionStorage Value="InProjectDir"/>
  8.       <MainUnit Value="0"/>
  9.       <Title Value="__PROJNAME__"/>
  10.       <Scaled Value="True"/>
  11.       <ResourceType Value="res"/>
  12.       <UseXPManifest Value="True"/>
  13.       <XPManifest>
  14.         <DpiAware Value="True"/>
  15.       </XPManifest>
  16.       <Icon Value="0"/>
  17.     </General>
  18.     <BuildModes Count="3">
  19.       <Item1 Name="Default" Default="True"/>
  20.       <Item2 Name="Debug">
  21.         <CompilerOptions>
  22.           <Version Value="11"/>
  23.           <PathDelim Value="\"/>
  24.           <Target>
  25.             <Filename Value="__PROJNAME__"/>
  26.           </Target>
  27.           <SearchPaths>
  28.             <IncludeFiles Value="$(ProjOutDir)"/>
  29.             <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
  30.           </SearchPaths>
  31.           <Parsing>
  32.             <SyntaxOptions>
  33.               <IncludeAssertionCode Value="True"/>
  34.             </SyntaxOptions>
  35.           </Parsing>
  36.           <CodeGeneration>
  37.             <Checks>
  38.               <IOChecks Value="True"/>
  39.               <RangeChecks Value="True"/>
  40.               <OverflowChecks Value="True"/>
  41.               <StackChecks Value="True"/>
  42.             </Checks>
  43.             <VerifyObjMethodCallValidity Value="True"/>
  44.           </CodeGeneration>
  45.           <Linking>
  46.             <Debugging>
  47.               <DebugInfoType Value="dsDwarf2Set"/>
  48.               <TrashVariables Value="True"/>
  49.               <UseExternalDbgSyms Value="True"/>
  50.             </Debugging>
  51.             <Options>
  52.               <Win32>
  53.                 <GraphicApplication Value="True"/>
  54.               </Win32>
  55.             </Options>
  56.           </Linking>
  57.         </CompilerOptions>
  58.       </Item2>
  59.       <Item3 Name="Release">
  60.         <CompilerOptions>
  61.           <Version Value="11"/>
  62.           <PathDelim Value="\"/>
  63.           <Target>
  64.             <Filename Value="__PROJNAME__"/>
  65.           </Target>
  66.           <SearchPaths>
  67.             <IncludeFiles Value="$(ProjOutDir)"/>
  68.             <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
  69.           </SearchPaths>
  70.           <CodeGeneration>
  71.             <SmartLinkUnit Value="True"/>
  72.             <Optimizations>
  73.               <OptimizationLevel Value="3"/>
  74.             </Optimizations>
  75.           </CodeGeneration>
  76.           <Linking>
  77.             <Debugging>
  78.               <GenerateDebugInfo Value="False"/>
  79.             </Debugging>
  80.             <LinkSmart Value="True"/>
  81.             <Options>
  82.               <Win32>
  83.                 <GraphicApplication Value="True"/>
  84.               </Win32>
  85.             </Options>
  86.           </Linking>
  87.         </CompilerOptions>
  88.       </Item3>
  89.     </BuildModes>
  90.     <PublishOptions>
  91.       <Version Value="2"/>
  92.       <UseFileFilters Value="True"/>
  93.     </PublishOptions>
  94.     <RunParams>
  95.       <FormatVersion Value="2"/>
  96.       <Modes Count="0"/>
  97.     </RunParams>
  98.     <RequiredPackages Count="1">
  99.       <Item1>
  100.         <PackageName Value="LCL"/>
  101.       </Item1>
  102.     </RequiredPackages>
  103.     <Units Count="2">
  104.       <Unit0>
  105.         <Filename Value="__PROJNAME__.lpr"/>
  106.         <IsPartOfProject Value="True"/>
  107.       </Unit0>
  108.       <Unit1>
  109.         <Filename Value="__PROJNAME__u.pas"/>
  110.         <IsPartOfProject Value="True"/>
  111.         <ComponentName Value="__PROJNAME__"/>
  112.         <ResourceBaseClass Value="Form"/>
  113.       </Unit1>
  114.     </Units>
  115.   </ProjectOptions>
  116.   <CompilerOptions>
  117.     <Version Value="11"/>
  118.     <PathDelim Value="\"/>
  119.     <Target>
  120.       <Filename Value="__PROJNAME__"/>
  121.     </Target>
  122.     <SearchPaths>
  123.       <IncludeFiles Value="$(ProjOutDir)"/>
  124.       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
  125.     </SearchPaths>
  126.     <Linking>
  127.       <Options>
  128.         <Win32>
  129.           <GraphicApplication Value="True"/>
  130.         </Win32>
  131.       </Options>
  132.     </Linking>
  133.   </CompilerOptions>
  134.   <Debugging>
  135.     <Exceptions Count="3">
  136.       <Item1>
  137.         <Name Value="EAbort"/>
  138.       </Item1>
  139.       <Item2>
  140.         <Name Value="ECodetoolError"/>
  141.       </Item2>
  142.       <Item3>
  143.         <Name Value="EFOpenError"/>
  144.       </Item3>
  145.     </Exceptions>
  146.   </Debugging>
  147. </CONFIG>
  148.  
  149.  


Perhaps you'll find what is wrong :)

B->
Dzandaa

Thaddy

  • Hero Member
  • *****
  • Posts: 12543
Re: Problem creating a Template for a Form
« Reply #4 on: November 27, 2022, 12:49:14 pm »
What is wrong is manually edit it: it is a generated file, don't touch it!
For other editors that file is not even necessary, just for Lazarus IDE. In general one would look for the lpr, not the lpi.
Maybe the lpi files should contain a warning about that.....
And it is NOT a template at all. It is configuration.
« Last Edit: November 27, 2022, 12:55:13 pm by Thaddy »
Writing code in an overly complex way is usually merely a complete misunderstanding of the goal you are trying to achieve.

ASerge

  • Hero Member
  • *****
  • Posts: 2049
Re: Problem creating a Template for a Form
« Reply #5 on: November 27, 2022, 02:37:23 pm »
Here is my __PROJNAME__.lpi
Strange. Everything seems to be right.
I took your file, added the __PROJNAME__.lpr file to the Test directory with content:
Code: Pascal  [Select][+][-]
  1. program __PROJNAME__;
  2. {$APPTYPE CONSOLE}
  3. {$MODE OBJFPC}
  4. {$LONGSTRINGS ON}
  5.  
  6. begin
  7. end.
and project.ini with content:
Code: INI  [Select][+][-]
  1. [Variables]
  2. [Project]
  3. Name=test
And according to this template, the project is successfully created and compiled.
Lazarus 2.2.4.

Dzandaa

  • Jr. Member
  • **
  • Posts: 89
  • From C# to Lazarus
Re: Problem creating a Template for a Form
« Reply #6 on: November 29, 2022, 07:13:27 pm »
Hi,

I'm not a specialist, but it seems that template doesn't work well with Lazarus Form and .lpi

Without .lpi you have a missing .lpi error
And with .lpi, you have invalid .lpi, just because in the .lpi "Project" is replaced by the name of your project.

Here is my template, it's just a Form with a button and a memo.

But perhaps my files are wrong :)

B->

Dzandaa

ASerge

  • Hero Member
  • *****
  • Posts: 2049
Re: Problem creating a Template for a Form
« Reply #7 on: November 29, 2022, 08:52:50 pm »
But perhaps my files are wrong :)
I created a simple form without controls. And it works for me.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4168
  • I like bugs.
Re: Problem creating a Template for a Form
« Reply #8 on: November 29, 2022, 09:25:08 pm »
Using Lazarus version 2.0.12 FPC 3.2.0 on Windows
The Project Templates package got fixes and improvements. I am not sure if they are included in the latest release but they are in "main" branch for sure.
In general, try a more recent version when you have problems. Lazarus 2.0.12 is not recent.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

PierceNg

  • Sr. Member
  • ****
  • Posts: 285
    • SamadhiWeb
Re: Problem creating a Template for a Form
« Reply #9 on: November 30, 2022, 12:57:52 am »
What is wrong is manually edit it: it is a generated file, don't touch it!
For other editors that file is not even necessary, just for Lazarus IDE. In general one would look for the lpr, not the lpi.
Maybe the lpi files should contain a warning about that.....
And it is NOT a template at all. It is configuration.

The configuration is generated from templates, and the OP is trying to create a new template.

Below is a 3rd party template for writing games for libretro in Lazarus:
Code: Text  [Select][+][-]
  1. % ls -l ~/.lazarus20/templates/libretro-fpc-template
  2. total 40
  3. -rw-r--r-- 1 pierce pierce  2352 Oct 10  2021 libretro.inc
  4. -rw-r--r-- 1 pierce pierce   699 Oct 16  2021 project.ini
  5. -rw-r--r-- 1 pierce pierce  2530 Oct 16  2021 __PROJNAME__.lpi
  6. -rw-r--r-- 1 pierce pierce 17343 Oct 10  2021 __PROJNAME__.lpr
  7. -rw-r--r-- 1 pierce pierce   959 Oct 16  2021 __PROJNAME__.lps
  8. -rw-r--r-- 1 pierce pierce  1993 Oct 10  2021 readme.txt
  9.  

And readme.txt says,
Quote
This is a Project Template for the Libretro-FPC package, and should contain the following files:

libretro-fpc-template
    __PROJNAME__.lpi
    __PROJNAME__.lpr
    __PROJNAME__.lps
    libretro.inc
    project.ini
    readme.txt (you are reading me now)

In order to use templates in Lazarus you need the "ProjTemplates" package installed in Lazarus, install it if y>
Let's say you run Windows and have a copy of Libretro-FPC in "F:\CoreFPC\libretro", in that folder you should h>
Next go to "Tools" -> "Project templates options..." in Lazarus to know or set the templates folder, next copy >
Now you should be ready to go, restart Lazarus.
...

Dzandaa

  • Jr. Member
  • **
  • Posts: 89
  • From C# to Lazarus
Re: Problem creating a Template for a Form
« Reply #10 on: December 01, 2022, 03:38:50 pm »
Hi everybody,

I've updated Lazarus to the last version and now templates are working.

Thank you.

B->
Dzandaa

Thaddy

  • Hero Member
  • *****
  • Posts: 12543
Re: Problem creating a Template for a Form
« Reply #11 on: December 01, 2022, 08:17:52 pm »
<sigh> these are not templates. They are config files.
Writing code in an overly complex way is usually merely a complete misunderstanding of the goal you are trying to achieve.

 

TinyPortal © 2005-2018