Templot Club Archive 2007-2020                             

topic: 2956Coding for beginners
author remove search highlighting
 
posted: 25 Dec 2016 14:28

from:

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
As I've mentioned in the past, Templot is written in Delphi, which is a visual version of Pascal.

Nowadays it is expensive to buy Delphi -- gone are days of free cut-down versions on computer magazine cover disks.

But Lazarus is an open-source clone of Delphi, works well, and is entirely free:

 http://www.lazarus-ide.org

If anyone is looking to try program coding, Lazarus is an excellent choice and easy to use.

Martin.

posted: 26 Dec 2016 09:14

from:

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
Well worth a look for anyone interested in programming, especially since it's free. :)

I used Delphi to write software to run the core of my business and it was so much easier to use than the competition - C++ at the time - and so much faster to compile. I could do almost interactive coding by writing a few lines, then compile and debug to see if they worked. With other compilers you could have a cup of tea while waiting for the compiled output. :)

Jim.

posted: 14 May 2017 00:06

from:

DerekStuart
 
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've just had a look at sample code for it and it seems very similar in idea to MS VBA and the old Commodore basic that I used in nineteen hundred and dark.

Presumably this is far, far harder to 'get into' though, is it?

posted: 14 May 2017 00:24

from:

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
DerekStuart wrote:
I've just had a look at sample code for it and it seems very similar in idea to MS VBA and the old Commodore basic that I used in nineteen hundred and dark.

Presumably this is far, far harder to 'get into' though, is it?
Hi Derek,

Which software are you referring to? I suggest you start with Lazarus, which is a clone of Delphi, works well, and is entirely free:

 http://www.lazarus-ide.org

How hard it is to "get into" depends on what you want to do. It is very quick and easy to write simple programs to do calculations, print lists of numbers, draw coloured diagrams on the screen, and so forth.

If you want to develop a replacement operating system for the NHS, it might take a bit longer. :)

If you say something simple I will post some sample code showing how you might get started, and you could have a go at changing it or expanding it.

regards,

Martin.

posted: 14 May 2017 15:24

from:

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
Hi Derek,

If you are starting Lazarus for the first time, you might find the screen confusing, even though it is really very simple, at least for Windows:

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-1.6.4-fpc-3.0.2-win64.exe

That's all you need, don't click any of the other 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, start Lazarus by clicking that desktop icon.

You will then probably see this:

2_141012_020000000.png2_141012_020000000.png

Which strikes me as not at all helpful for a beginner. Don't change anything on there, just click the Start IDE button.

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

If you have got that far and wondering what to do next, I can suggest some basic stuff to create and run a simple test program.

p.s. "IDE" means "Integated Development Environment" which is just a fancy name for the normal Lazarus desktop screen -- see:

 http://en.wikipedia.org/wiki/Integrated_development_environment

regards,

Martin.

posted: 20 May 2017 12:08

from:

DerekStuart
 
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
Hello Martin
Many thanks for the info. Much appreciated.

"If you say something simple I will post some sample code showing how you might get started, and you could have a go at changing it or expanding it."

From the examples I've looked at, it seems fairly intuitive. Using Templot's purpose as an example: It seems a programme to allow the plotting of 2 curves of X dia. Y length and intersecting at Z would be fairly straight forward (from what I've seen). But the one bit I was never any good at was GUIs- ie, click on the curve and move it to "over there", but that would be well beyond what I could expect anyone to explain on a discussion forum.

I will let you know how I get on. Thanks.

posted: 20 May 2017 15:36

from:

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
DerekStuart wrote:
But the one bit I was never any good at was GUIs- ie, click on the curve and move it to "over there", but that would be well beyond what I could expect anyone to explain on a discussion forum.
Hi Derek,

I will see what I can do. :)

regards,

Martin.

posted: 20 May 2017 23:35

from:

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
So let's try something.

The first thing to do is create a folder in a known place to contain your files. There will be quite a few of them. I much prefer to do this rather than rely on the default Windows behaviour of using virtual folders from which it is always a pain to find what you are looking for. You will need to access the folder directly, because in there will be the final executable program file.

I created a folder called C:\DEREK_TRIAL\ for this example program.

This is what you will see when you run Lazarus:

2_201613_280000000.png2_201613_280000000.png

Lazarus (and Delphi) scatter themselves 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 program which you are creating. 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.

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 appears in a separate tab in the editor window. Small programs often have only one form and one corresponding unit. 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.

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

The Object Inspector is currently showing the settings for the form object. 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 initial changes:

Every object in Lazarus must have a name, so that it can be referred to in the code. For this form you can see that I have given it the name derek_form. 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 derek, DEREK, Derek, DERek, dEreK, 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 result when reading code that I can see immediately which names were created by me, and which were created by Lazarus. So this form is called derek_form.

Next we need to set the text which appears in the title bar at the top of the form. 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 "Trial Program For Derek". As it is typed in the Object Inspector it appears on the form.

I then saved the project so far, such as it is, by clicking File > Save As... on the top window.

This is a bit tedious, but gives you a chance to set up the file names for this project. You need only do this once. There are several files to be saved in our new folder, each one will appear in turn in the Save dialog:

The project file has the extension .lpr and contains the code for the main executable startup program. I called it derek_project.lpr       

The same name will be used for several other files, such as the final executable program, derek_project.exe

Then the file containing the unit must be named and saved. The file has the extension .pas and contains the code text from the editor window. I called it derek_main_unit.pas and you can see that Lazarus updated the unit name on the first line in the editor accordingly.

Lazarus will then automatically create the linked file derek_main_unit.lfm which contains details of the corresponding form window, such as the size and position of each button.

Having done all that the project can be opened and saved in future simply by opening the project file.

So we are now ready next time to make the program actually do something. :) 
 
regards,

Martin.

posted: 30 May 2017 23:44

from:

DerekStuart
 
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
Hello Martin
Thanks for the further info. I must admit that at first I came close to testing the flight characteristics of HP laptops.

But I have downloaded it to the work desktop- faster and with a bigger screen- I have been able to "play" with the interface and get to understand it a bit. I have found example codes on the internet and will try to reverse engineer little bits of it and see what it does.

Thanks for the encouragement. I shall let you know how I get on, but don't expect miracles as it's taken 3 years to be able to solder track properly.

posted: 31 May 2017 14:20

from:

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
DerekStuart wrote:
I must admit that at first I came close to testing the flight characteristics of HP laptops.
Hi Derek,

Yes, I've been there many times. I suspect many Templot users too. :)

Sorry about the delay in getting back to you. I have created a small program which you might like to try making and modifying. You specifically asked about drawing on the screen.

The executable is attached below.

It is unsigned, so you will need to click through the security warnings.

I will post the code later. Unlike web examples, you can ask me what each bit means. :)

regards,

Martin.
Attachment: attach_2445_2956_derek_project.exe     313

posted: 31 May 2017 14:59

from:

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
Hi Derek,

You need to put 4 objects on the form:

2_310928_040000000.png2_310928_040000000.png

1. From the Standard tab, select a TButton (they describe themselves if hovered over), click and drag a rectangle for it on the form.

On the Object Inspector window , give it the Name colour_button, and the Caption choose background colour.

2. Add another one on the form. Give it the Name go_button, and the Caption GO.


Those are the visible controls. Now you need two "designers". These objects appear on the form at design time, but not when the program runs.

3. From the Dialogs tab, select a TColorDialog, add it on the form.

On the Object Inspector, give it the Name derek_colour_dialog.


4. From the System tab, select a TTimer, add it on the form.

On the Object Inspector, give it the Name derek_timer, set Enabled to False, and set the Interval to 20 (milliseconds).


Here is a zip file containing all that and the code. Extract it to a folder somewhere.

Code to follow.

regards,

Martin.
Attachment: attach_2446_2956_derek_lazarus_zip.zip     320

posted: 24 Sep 2017 15:52

from:

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
Hi Derek,

Sorry I haven't got back on this topic over the summer.

But it's not forgotten. Are you still interested?

regards,

Martin.

posted: 30 Sep 2017 13:09

from:

DerekStuart
 
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
Hello Martin

My apologies that I never even replied to thank you. Unfortunately I was 'indisposed' for a while and lacking any enthusiasm except for a quick flick through forums, but it seems that I am actually immortal after all (subject to a 6mth check up).

So now, I'm back with an insatiable enthusiasm to learn coding, climb Kilimanjaro, run the Marathon and possibly even print out my Templot files and make a start on rebuilding the entire East coast in S4.

One thing I would like to share with anyone who might read this- life is short, far too short to put everything on the round-tuit shelf. I was very lucky and have a second chance; I do not intend to waste it.

posted: 9 Oct 2017 01:06

from:

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
Hi Derek,

Thanks for your message.

Sorry to hear you have been ill, but glad to know you are now feeling better. :thumb:

best regards,

Martin.

posted: 6 Nov 2017 00:59

from:

DerekStuart
 
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
Hello Martin

After my first "proper" day of looking at this, it has proven to be a lot easier to follow than I expected. Nothing flashy, just seeing how to make it accept data and then reprint it on screen, add up, divide and so on (yes, my own personalised calculator).

One question if I may, if I want to save that data to a database, do I have to use SQL or similar as the 'back office' database driver or can Lazarus save the data directly as a file?

I think HOW to do that is beyond what is fair to ask of you, but if I know whether it can do it then I can search for examples.

Thanks again for the encouragement on this; I really wish I'd pulled my finger out and pursued this earlier as it's quite good fun.

EDIT: Isn't that typical... less than 5 minutes after typing that I've just found an example; it's only to write to a text file but it's a start.
Last edited on 6 Nov 2017 01:03 by DerekStuart
posted: 6 Nov 2017 01:42

from:

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
Hi Derek,

Sure you can create a full database, but it's a massive overkill just to save data to a file.

For text data, one of the easiest ways is to use a TMemo component. (6th item in the Standard controls).

Add it to the form and drag it big enough to type in.

Any text in there can be saved to a file with one line in a button click:

 derek_memo.Lines.SaveToFile('C:\MY_STUFF\banana_growing_in_norway.txt');

Or to open a text file: .Lines.LoadFromFile('C:\MY_  ...

Programmatically you can access individual lines of text as Lines.Strings[n]; (first line is 0), or the whole block of text as the string: Lines.Text;

To add a new line programmatically: .Lines.Add('some text');

The TMemo.Lines property is a TStringList which is one of the most useful objects in Delphi/Lazarus because of the ease of saving and loading text files, and the ability of attaching any TObject to each line. Such as a TBitmap for example to create a list of images, or even a nested TStringList, etc. to create an entire photo album or slideshow.

Glad you have made a start -- coding is fun. :)

cheers,

Martin.

posted: 6 Nov 2017 08:49

from:

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
DerekStuart wrote:
One question if I may, if I want to save that data to a database, do I have to use SQL or similar as the 'back office' database driver or can Lazarus save the data directly as a file?

Derek,

If Martin takes you on to the Object Oriented aspect of Delphi/Lazarus,  for small database projects you could create a database object to store your data and create all the necessary functions to parse and store all the fields in your data as well as performing actions on the data..   I did this for an application I wrote for my business and it meant that I could really fine tune how my database was handled without using SQL, etc.   The database information didn't need to be exported as such so there was no need to conform to standards.

Jim.

posted: 6 Nov 2017 11:38

from:

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
Jim Guthrie wrote:
If Martin takes you on to the Object Oriented aspect of Delphi/Lazarus, for small database projects you could create a database object to store your data
Hi Jim,

Why me? How about you? :)

Actually I have done very little database programming. A database is great if you want to sift and sort data, but it's not really needed just to store it. You can create your own data structures to suit your data, and then you have total control and don't need to rely on a database engine to access it.

For example there is no database in Templot.

Likewise there is not a great deal of Object Oriented* stuff. The sketchboard is done that way, but most of the original Templot code uses traditional procedural programming. I might do things differently if starting again, or maybe not. :?

*OO programming. :)

cheers,

Martin.

posted: 6 Nov 2017 16:06

from:

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
Martin Wynne wrote:
Why me? How about you? :)

Actually I have done very little database programming. A database is great if you want to sift and sort data, but it's not really needed just to store it. You can create your own data structures to suit your data, and then you have total control and don't need to rely on a database engine to access it.

For example there is no database in Templot.

Likewise there is not a great deal of Object Oriented* stuff. The sketchboard is done that way, but most of the original Templot code uses traditional procedural programming. I might do things differently if starting again, or maybe not. :?

*OO programming. :)
Martin,

I haven't done any programming since I retired about seven years ago so I suspect I would have to go back to school again. :D

I think we might also argue about semantics again (a regular feature of the Templot forum :) :) ) but I would argue that what the Storage Box is looking at in Templot is a database - i.e. a list of records of each template with all the data associated with the templates whicn is designed to suit the particular requirements of Templot.

I also thought you might have dabbled in OOP since it can make life a lot easier than procedural programming,  especially when you want to dive in and change things. :D :D :D

Jim.

posted: 6 Nov 2017 17:19

from:

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
Hi Derek,

You may have noticed something about programmers -- no two of them ever agree. :)

In case you are wondering:

Procedural Programming (PP):

"I am a function to draw track templates on the printer page. Which one would you like me to draw?"

Object-Oriented Programming (OOP):

"I am a track template. Where would you like me to draw myself?"

Programs such as Delphi/Lazarus tend to assume you will use OOP, but you don't have to take any notice.

Hi Jim,

By database I mean something like MySql which is accessed using a query language to create tables and fields, and extract the contents according to rules. For which you need a database engine to maintain it.

Templot doesn't contain anything like that (and when I started on it in 1979 I knew nothing about such things). The Storage Box is simply a list, actually a TStringList.

Everyone told me OOP was the way to go, but when I tried it I couldn't see any advantage, and it made debugging much more difficult. Also it hadn't been available for the first 20 years of Templot -- so it was far easier to port the existing code into Delphi than rewrite everything in a new and strange way.

Some of the code in Templot goes right back to the early 1980s. Some of the global variable names are even older and still the same 2-character symbols going back to the first ever version in 1979. Anyone else reading the code would find them unintelligible, but I can read them as old friends.

cheers,

Martin.

posted: 6 Nov 2017 21:24

from:

pointo1d
 
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
Personally I've noticed that, in the world of software, the latest (and not necessarily greatest) things are always, in my view wrongly, promoted as the golden bullet; I am and always have been, a devotee of the good old "horses for courses" adage along with "if it ain't broke, don't fix it".

On a side note and FWIW, I notice that the Lazarus IDE is also available, through the standard repositories, to Ubuntu (and presumably other Linux distro) users.

Best rgds to all,
Dave P

posted: 7 Nov 2017 09:15

from:

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
pointo1d wrote:
Personally I've noticed that, in the world of software, the latest (and not necessarily greatest) things are always, in my view wrongly, promoted as the golden bullet; I am and always have been, a devotee of the good old "horses for courses" adage along with "if it ain't broke, don't fix it".

Dave,

If you are inferring that Object Oriented Programming is one of the latest and greatest programming features,  then the earliest OOP language, C++,  has been around since the early 1980s.  Borland Delphi,  which Martin and I use, was around since 1995, and more recent, popular languages like Java and Python are OOP.   Martin's basic engine that drives Templot was probably well developed using structural programming methods when Delphi appeared and Martin chose to leave it as it was.  In my case,  I was developing a program which would handle data from three sources and the encapsulation features of OOP were a big help in protecting the program from its author.  :D :D :D

Jim.
Last edited on 7 Nov 2017 09:19 by Jim Guthrie
posted: 7 Nov 2017 11:46

from:

pointo1d
 
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
Hiya Jim,

That wasn't my inference per-se ... but your example, I believe, proves my "horses for courses" point in as much as your chosen OOP language provided the sought-after encapsulation; Although I have to say I wish I'd thought of choosing an implementation language to protect my program from me (Y) (Y)

posted: 29 May 2018 13:54

from:

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
For anyone following this topic in Lazarus, you might like to look at this free PDF download eBook:

"FreePascal from Square One":

 http://www.contrapositivediary.com/?p=4034

Actually that should be square zero because it literally starts from the very beginning for anyone wanting to try coding -- chapter 1 starts with coffee and scrambled eggs. :)

FreePascal is the compiler used in Lazarus.

Here's a repeat of the actual download link:

 http://www.copperwood.com/pub/FreePascalFromSquareOne.pdf

Martin.

posted: 29 May 2018 15:55

from:

wcampbell23
 
Hamilton, Scotland - 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
Martin - you are a seriously bad influence.

I had a quick look at "FreePascal from Square One" and decided that I liked the style of writing so much I will have to sit down and read it properly.

Mind you I agree about starting from zero - one of the things I had to teach kids so that they could learn how to count properly.

Best wishes

Bill Campbell.
Last edited on 29 May 2018 15:56 by wcampbell23
posted: 9 Jun 2018 20:50

from:

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
Now that TemplotMEC is released, I'm closing this topic, and continuing it here:

 topic 3283

Martin.



Templot Club > Forums > Off track > 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