[Lazarus] How to add your own 'New Project' template?

Tom Verhoeff T.Verhoeff at tue.nl
Fri Aug 22 13:06:50 CEST 2008


On Fri, Aug 22, 2008 at 09:25:23AM +0200, Michael Van Canneyt wrote:
> > 
> >  7. It is not clear to me what the requirements are for naming files
> >     in the template, and how these names get changed when the template
> > is instantiated.  Should I put files like project.ini, project.lpi,
> > project.pas, unit1.pas in the template directory, and will
> > project.{lpi,pas} be renamed depending on the name chosen by
> > the user when instantiating the template?  That is, are there
> > more substitutions than just for the occurrences of $(varname)
> > in non-Exluded files, viz. file name changes?
> 
> No. Any substitution must be marked as such. There are no 'special'
> cases, but if you want to send some patches to handle this, let me know.

What you mention concerns substitutions _inside_ the (text) files.  What I
was aiming at is substitutions of the _names_ of files being copied.
Assuming we have in project.ini:

[Project]
Name=Special
Author=Tom
Description=A special FreePascal program.
Recurse=0
Exclude=.lrs

[Variables]
special=Example

Using the template below on the left creating a new project with
project name 'my_new_proj' in directory 'My New Project', you get 
the instance on the right:

Template dir	Transformation	Instantiated dir
------------	--------------	----------------
project.ini	not copied
project.lpi	substituted	my_new_proj.lpi
project.lpr	substituted	my_new_proj.lpr
main.pas	substituted	main.pas
main.dfm	substituted	main.dfm
main.lrs	copied as is	main.lrs
aux.pas		substituted	aux.pas

where 'substituted' means that in the contents of the file,
the following substitutions are carried through while copying:

$(ProjName)	->	my_new_proj
$(ProjDir)	->	My New Project
$(special)	->	Example

In the README for components/projecttemplates is says:

	During the copy, the package will scan the file/directory names and the 
	contents of the files for variable substitution: $(VARNAME) will be 
	replaced by the value of a variable $(VARNAME).

This suggests that substitutions are also done for file names (as
well as the file contents).  But how should one name the files,
to get their names substituted?  Should they rather be called

$(ProjName).lpi
$(ProjName).lpr

This is rather awkward for a file name.  Please confirm.

Thanks,

	Tom
-- 
E-MAIL: T.Verhoeff @ TUE.NL     | Dept. of Math. & Comp. Science
PHONE:  +31 40 247 41 25        | Technische Universiteit Eindhoven
FAX:    +31 40 247 54 04        | PO Box 513, NL-5600 MB Eindhoven
http://www.win.tue.nl/~wstomv/  | The Netherlands



More information about the Lazarus mailing list