Templot Club Archive 2007-2020                             

topic: 3283Getting started with TemplotMEC - coding for beginners
author remove search highlighting
posted: 9 Jun 2018 20:42


Martin Wynne
West Of The Severn - United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
This topic assumes you are using Windows.     topic updated 5th July 2018


Now that I have posted the open-source code for Templot, you might want to join in the developments. Or use Templot as a basis to learn some coding. If there is something in Templot which you have always wanted to change, now is your chance. :)

There is the Templot3 Project which might one day replace Templot2, see:


Or alternatively you might like to try the TemplotMEC option so that you can dabble in coding on your own personal version of Templot.
If so, the first thing to do is to download and extract the open-source TemplotMEC files. They are in the zip file at:


Create a new folder somewhere on your system to unzip the file into.

It can be anywhere you like, called whatever you like,


1. NOT in your existing Templot2 folder (\TEMPLOT_DEV\).

2. NOT in the Windows \Program Files\ folders.

3. NOT containing any spaces anywhere in the folder name or the path to it.

I suggest C:\TEMPLOT_MEC\ or maybe on an external drive or USB stick.

After extracting it into that folder, you will have a sub-folder containing the files, like this:


I suggest that you copy all the files from the sub-folder into the main folder:


These then become your working files, to edit the nuts and bolts as you wish. The files in the sub-folder remain unchanged as a backup if the wheels fall off your program. :)

They are in plain text, so you could open and read them in Windows Notepad (other text editors are available).

But to make any use of them you need a compiler. A compiler is a program which reads the statements which are written in the source code files, and converts them into a runnable computer program, called the object code.

The files are intended to be used with the Lazarus/FreePascal compiler system, which is free.

To download and install Lazarus:

1. go to http://www.lazarus-ide.org

2. click the Download Now button.

After a few seconds you will be downloading the file: lazarus-2.0.6-fpc-3.0.4-win64.exe

That's all you need, don't click any of the other advertising stuff on the Sourceforge pages which might flash up.

Download that file and run it to install the Lazarus program in the usual way. Being free, they aren't paying fees for a digital certificate, so you will need to click past the security warnings (same as for Templot).

During the install process you will probably find it convenient to tick the "create desktop icon" box.

When installation finishes (it may take a while), start Lazarus by clicking that desktop icon.

3. you might then see this:


Don't change anything on there, just click the Start IDE button. "IDE" means "Integated Development Environment" which is just a fancy name for the normal Lazarus desktop screen.

You won't see this again next time you start Lazarus.

4. click the File > Open... menu item, and navigate to the previously downloaded TemplotMEC files. Select and open the file:


5. answer Yes or Open Project to any questions which come up.

6. You should then be seeing something like this (the windows may be arranged differently):


7. if the Project Inspector window is showing (not the Object Inspector), you can close it.

8. if the Source Editor window is missing or empty, click the Project > Units ... menu item, and select control_room.pas from the list.

You are now ready to try compiling TemplotMEC. :)

9. as this is a first try, it's best to do a full build to check for errors before running. Click the Run > Build menu item:


10. it will take a while -- the Messages window will appear and fill with messages.

There will be several Warning messages, but hopefully no red Error messages. The warnings will need to be fixed in due course, especially if you want to port TemplotMEC to some other platform such as Linux or Mac. But for now they are not serious on Windows and can be ignored.

The word which you are looking for is "Success" on a green background. :)

It should appear eventually:


11. assuming you get a green, it's finally time to try running it. Click the Run > Run menu item:


12. it will again take a while, and the Messages window will appear again. But eventually you should see the familiar Templot start-up:


13. and if you click GO, you should have TemplotMEC running. :)

Note (debugging...) shown in the Lazarus top bar. This means that TemplotMEC is currently running inside Lazarus, and you should get meaningful error messages if there are any. But TemplotMEC will be fully functional and usable in that condition.

N.B. note that you won't be able to load any of your existing Templot2 .box files. But you should be able to create TemplotMEC track plans, save them, and reload them, in .otbox format. And print them.

Likewise your existing .bgs files, and printer calibration files.

The file conversion functions will be available in the next Templot2 program update soon.

More next time.



posted: 10 Jun 2018 04:26


Martin Wynne
West Of The Severn - United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
Lazarus scatters itself across the screen in 5 basic windows.

Each one can be moved around and re-sized in the usual way, to suit yourself:


1. is the main command window. Closing this closes Lazarus. Minimizing this minimizes everything.

2. is the window representing the part of the program which you are working on. This is where you drag and drop the buttons and boxes which make up your program. The dots are a grid to which they can be aligned for a neater result. The dots don't show when the program runs. Program windows are called Forms. The data for a form is saved in a .lfm file.

3. is the Editor window. This where you write the code which makes things happen when the buttons and boxes are clicked. Each form has its own corresponding chunk of code, called a Unit. Each unit is saved in a separate .pas file with the same name as the corresponding form file.

Each unit appears in a separate tab in the editor window. The current tab being edited is highlighted. An asterisk against the file name in the tab indicates that the contents have been changed and will need saving.

The editor and form windows can be toggled to and fro in front of each other by pressing F12 on the keyboard -- which is handy if you are working with large forms on a small screen.

The font used in the editor needs to be a fixed-width font if you value your sanity, so that the text appears in fixed columns. By default the font used is Courier New, but I find the Consolas font is easier on my eyes.

The editor changes the colours of the text according to its meaning to the compiler. This is called "syntax highlighting". This is very useful to avoid typing errors. The colours and formatting can be changed to whatever you find comfortable.

Chunks of text can be hidden from view by clicking the small + and - boxes on the left. This is called "folding" the text. It is very useful to reduce scrolling when working on a long unit.

4. is called the Object Inspector window. This is where you make the settings for each Object in the program by entering them in the right-hand column. For example if you add a button to a form, this is where you set the text which appears on the button. Almost everything in Lazarus is an object, so this Object Inspector window is used a lot. It is typically arranged as a tall column window. Most programmers seem to like it on the left of the screen, but I prefer it on the right.

5. is the Messages window. This is where Lazarus reports what's happening -- hopefully on a green background to indicate a successful operation. You can close this window when not needed and it will re-appear when there is something to report.

Other smaller dialog windows appear in the usual way as needed.

In the screenshot above I am editing the control_room unit. Users who were in at the first release of Templot in 1999 will recognise these names. This window is now called the program panel, but it was then called the "control room". I changed it on the visible window to avoid confusion with the control template, but the original names in the code haven't changed.

Likewise the storage box is in the keep_select unit. Stored templates were then called "keeps". I was persuaded to change the name by Brian Lewis (then of C&L), but I often regret it. You will find the term "keep" for a stored template is still used throughout the code.

The Object Inspector above is currently showing the settings for the recent files button object. You can see that I have clicked on it, and it has gained some corner handles which could be used to drag it around and resize it.

The form is shown at design-time with all objects visible. When the program is run they are not necessarily all visible at the same time. On this window the blue bar behind the buttons is not visible at the same time as the row of buttons.

Lazarus makes some default settings when an object is created. Most of them can be left on the defaults, but you will always need to change a few of them. As you can see I have made some settings:

Every object in Lazarus must have a name, so that it can be referred to in the code. For this button you can see that I have given it the name recent_button. Spaces are not allowed in names. It could be called anything (beans_on_toast ?) but it is handy to use a sensible name and include a reference to the type of object. Otherwise when you come to read the code again in a few years time (or in my case 5 minutes later) it will be meaningless.

Lazarus is case-insensitive, so recent_button, RECENT_BUTTON, Recent_Button, reCenT_buTton, all mean exactly the same thing and refer to the same object. Lazarus itself uses camel-case, so that objects and functions have names such as ToggleBox or SaveToFile.

You can do the same if you wish for names, but I prefer to use all lower case separated by underscores: toggle_box, save_to_file. This has the useful advantage when reading code that I can see immediately which names were created by me, and which were created by Lazarus.

Next we need to set the text which appears on the button. This text is called an object's Caption. Generally the text which appears on the screen on a button, next to tickbox, etc., is called its caption. As you can see I have set this to "&recent  files". I often use a double space for easier reading. The &ampersand causes the next letter to appear underlined on the button as a keyboard accelerator key.

You can see some of the other settings, all of which can be changed. The Height of the button is set to 29 pixels. Left means the left edge of the button is 91 pixels from the left edge of the form.

More below.


posted: 10 Jun 2018 20:14


Martin Wynne
West Of The Severn - United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides
You can now have some fun by changing some of the code, or changing details on the forms, such as maybe the background colour, and recompiling the program. :)

But some of the forms in TemplotMEC use an add-on component (a mini-browser) to display the Help notes, and some other content such as the program preferences dialog and the notes panel on the new template dialog (mint_unit/mint_form).

If you want to edit those forms, you will need to install the HtmlViewer add-on component in Lazarus -- it's called a "package". Otherwise Lazarus will display an error message when you press F12 on those units to see the forms.

If you begin writing other programs it will be a very useful component to have available in Lazarus.

Installing packages is not for the faint-hearted, so I have prepared a step-by-step sequence:

The easy way is to use the Online Package Manager:


If you can see the above menu item, jump to step 6.

If that isn't showing already installed, you will need to install it:

1. click the Package > Install/Uninstall Packages... menu item:


2. this dialog will appear. Scroll down the right-hand list and select onlinepackagemanager. Then click the Install selection button:


3. then click the Save and rebuild IDE button:


4. click Continue to confirm:


5. the process will take a while, after which Lazarus will restart from scratch.

6. but now there is a new item on the Package menu. Click the Online Package Manager menu item:

(An internet connection is needed to search for online packages.)

7. after a while this dialog will appear. Scroll down the list and tick the box next to HtmlViewer, then click the Install button. If there is a choice click install from repository.


Note in passing some of the other useful packages that you might one day want to install. :)  There are 140 of them listed at present.

8. click Yes to confirm:


9. the process will take a while, after which Lazarus will restart again. But this time if you look in the component bar you will see that the HtmlViewer is now installed:


10. which means you are now able to edit the forms without any error messages.



posted: 22 Oct 2019 11:20


Jim Guthrie
United Kingdom

click the date to link to this post
click member name to view archived images
view images in gallery view images as slides

I'll put this in this thread since that might be the correct one. :)

But for those who might be interested in using the free Delphi IDE or the Lazarus IDE, there's an option to download a free PDF of Marco Cantu's latest ebook on Object Pascal, the OOP language used in Delphi and Lazarus.

The URL for the small amount of hoops you have to jump through is here :-


I signed up for it last night and it seemed to accept my request. I am a member of the Embarcadero Developer's Network but I don't think that gave me any advantages for the offer. I got an email this morning with a URL pointing to the download source and it downloaded no problem.

I've only given it a cursory glance so far but it looks as though it might reference Delphi 10.1 when involving IDE matters but Delphi 10.3, the present free version, is not too much different, certainly for programming basics.

Cantu has a good reputation for his past books on Delphi.

Last edited on 22 Oct 2019 11:21 by Jim Guthrie

Templot Club > Companion > Videos and tutorials > Getting started with TemplotMEC - coding for beginners
about Templot Club

Templot Companion - User Guide - A-Z Index Templot Explained for beginners Please click: important information for new members and first-time visitors.
indexing link for search engines

back to top of page

Please read this important note about copyright: Unless stated otherwise, all the files submitted to this web site are copyright and the property of the respective contributor. You are welcome to use them for your own personal non-commercial purposes, and in your messages on this web site. If you want to publish any of this material elsewhere or use it commercially, you must first obtain the owner's permission to do so.
The small print: All material submitted to this web site is the responsibility of the respective contributor. By submitting material to this web site you acknowledge that you accept full responsibility for the material submitted. The owner of this web site is not responsible for any content displayed here other than his own contributions. The owner of this web site may edit, modify or remove any content at any time without giving notice or reason. Problems with this web site? Contact webmaster@templot.com.   This web site uses cookies: click for information.  
© 2020  

Powered by UltraBB - © 2009 Data 1 Systems