Templot Club Archive 2007-2020                             

topic: 3607Making sense of program code in Lazarus
author remove search highlighting
 
posted: 8 Feb 2020 15:31

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
Sorry, I can't find the thread you discussed this, but could you add me to the list of those who can view the development sub-forum, please?

I am particularly looking for the thread where you described how to get started with programming (the link to the compiler and there were a couple of useful sites you suggested for further guidance.)

I'm afraid I'm not about to develop Templot 3 any time soon, but I'm hoping to get beyond "Hello World."

Many thanks
Derek

posted: 8 Feb 2020 15:48

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
Thanks Martin. I can see it now.

A nice weekend of reading awaits (not to mention some headaches no doubt).

Derek

posted: 8 Feb 2020 15: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
Hi Derek,

You are now green. :)

You should now be able to see:

 http://85a.co.uk/forum/view_forum.php?id=26

although there hasn't been much activity recently. See also:

 topic 3539

The original "starting with Lazarus" topic is at:

 topic 3283

although I think it might need some updating. The latest set of files is at (click the Files tab):

 http://sourceforge.net/projects/opentemplot/

including the MECBOX option to import files from Templot2.

Ask again if you can't find anything -- things had got into a bit of a muddle. There is an option to try T3 directly within the latest Templot2 program update --T3 > run Templot3 menu item.

cheers,

Martin.

posted: 8 Feb 2020 16:04

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
Many thanks Martin. I really appreciate it.

I really don't want to bother you with questions, but if I could ask one in order to point me in the right direction.

If you were starting programming Templot from scratch now, would you still use a Pascal-based language? The internet is full of people with very definite opinions either way.

Thanks
Derek

posted: 8 Feb 2020 16:21

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:
If you were starting programming Templot from scratch now, would you still use a Pascal-based language? The internet is full of people with very definite opinions either way.
Hi Derek,

Yes, I think I would still choose Pascal.

20+ years ago before starting to port Templot to the Windows OS I did try a couple of other languages (Visual Basic and C), and didn't feel comfortable with either of them. After all this time wedded to Pascal I doubt I would find them any more appealing now.

I do like a strongly-typed language. Working in Javascript drives me nuts when I can never be quite sure whether I'm dealing with an integer, a float, a string, an array, or whatever. Leading to lots of quoting errors.

But I don't think you should take too much notice of what I think -- I'm a bit set in my ways these days. :)

However, Templot3 is staying in Lazarus -- unless or until someone other than me tries porting it elsewhere.

cheers,

Martin.

posted: 14 Feb 2020 09: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
Hi Derek,

Embarcadero have just launched a new site for learning Delphi and Pascal:

 http://www.learndelphi.org/

No doubt they will be pushing Delphi rather than Lazarus, but the basics are the same and the content there is released under Creative Commons. Worth watching.

cheers,

Martin.

posted: 16 Feb 2020 12:49

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 both posts. Opinion on languages is, as usual, divisive, but it seems that Pascal and its derivatives are generally well respected. As it's something where I can easily look at existing code, it seems logical to stick with it.

I've just opened learndelphi.org and immediately found a good looking beginners guide in PDF- exactly what I was looking for (I've also ordered a couple of books from Waterstones too).

Progress is slow, I'm afraid, but when I get something to work it gives a sense of achievement that I must admit is a little addictive.

Thanks
Derek

posted: 16 Feb 2020 15:01

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:
Progress is slow, I'm afraid, but when I get something to work it gives a sense of achievement that I must admit is a little addictive.
Hi Derek,

I agree. It can be very slow at the start because there is almost too much to take in, and you have nothing but a blank screen in front of you. I had the great advantage of having the existing Templot program to convert to Delphi, and I could therefore ignore all the stuff I didn't need.

Bear in mind that Delphi is primarily intended for corporate and business applications which display a lot of text and text entry boxes, and reference the data in a complex database structure. None of that was relevant to Templot, so I could cheerfully ignore at least 50% of the developer docs -- and I still wouldn't know where to start in developing a Delphi database or a business-style application. :)

My advice would be to start with a simple but interesting core application onto which you can bolt and unbolt extra features as you dream them up. That way you can learn what works and what doesn't as you go along, without losing the core part as a working fallback.

For example, you might start with a program which lays a row of bricks across the screen. Then another row on top of it. Then stagger them in a proper brick-bond pattern, needing some half-bricks at the end of the rows. Then spaces for some mortar between the bricks and rows. Then a whole wall. Then put in a doorway. Then a window. Make it a shop window. Put a can of baked beans in the shop window. Then a pile of cans. Then some boxes of cornflakes. Ask the user how many of each they require, and remove them from the pile. Put a canopy over the window to keep the rain off. Make it an arched doorway. Put a nameboard over the shop. Ask the user for its name and phone number. Make a whole row of shops. Print a list of their postcodes. Make one of them a post office...

In the end you might have something actually usable on your layout... :)

cheers,

Martin.

posted: 16 Feb 2020 23:19

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
Thanks Martin

I've learned a fair bit of lower level languages- VBA, Commodore basic, even html, by reverse engineering. A crude way of just deleting random lines to see what stops working.

But all the available sample code is either terribly simple or terribly complex... or just terrible.

I guess you mean the bricks being drawn dynamically as opposed to detailing the size and 0,0 point of each one. Ie "draw a brick x pixels wide, draw second brick at x+1 pixel and then draw..." I think I could work out how to do that, but not how to control when it comes to the end of the window.

I shall experiment and let you know when I've achieved it- or failed, as the case may be.

Derek

posted: 17 Feb 2020 00:03

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 guess you mean the bricks being drawn dynamically as opposed to detailing the size and 0,0 point of each one. Ie "draw a brick x pixels wide, draw second brick at x+1 pixel and then draw..." I think I could work out how to do that, but not how to control when it comes to the end of the window.

I shall experiment and let you know when I've achieved it- or failed, as the case may be.
Hi Derek,

I didn't necessarily mean that you should do any of that. :) It was just the first thing that came into my head to illustrate the Meccano method that I use -- bolt something on, see if it works, if not scrub it out and bolt something else on instead...

There are various ways of doing it. For example a brick wall is quite similar to the staggered printer page outlines in Templot, so you could have a look at how those are drawn on the screen.

Or the OOP approach would be perhaps to have a class called row_of_bricks, give it properties such as the number of bricks and the size of each, and a method to draw itself at a given location on the screen. That could mean drawing the brick outlines, or you could find a nice photo of a brick, and create a row of TImage components on the screen. Or use TShapes rectangles in varying shades of brick red. With a mortar-coloured border.

You could make each brick clickable so that when clicked it becomes transparent, to gradually reveal a photograph behind. That might make a children's game to see how few bricks they can remove in order to discover what's behind the wall. Or make each brick play a tune... :)

cheers,

Martin. 

posted: 17 Feb 2020 17:15

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
As ever, your comments are appreciated. I think the brick wall exercise is a good one, especially for what I'd like to eventually learn to do.

I've just found a couple of lines of code you've written:

// Windows.SetParent(data_child_form.Handle,pad_form.Handle);

// 292...

if data_child_form.Parent<>nil
   then data_child_form.Parent.RemoveControl(data_child_form);

pad_form.InsertControl(data_child_form);

The whole structure seems remarkably similar to VBA. I am not an expert in VBA by any means, but I can make MS Access do whatever I want with it. I was experimenting with using VBA to control MS SQL server- though with limited success.

Oddly, using VBA I think I could probably achieve both of your examples.

Thanks
Derek

posted: 17 Feb 2020 18:11

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:
Oddly, using VBA I think I could probably achieve both of your examples.
Hi Derek,

I confess that I had to Google VBA to find out what it is. :(

It seems to be a variant of VisualBasic6, which is no longer supported by Microsoft since the introduction of .NET around 2006. It seems odd that Microsoft are keeping it alive as VBA within its Office products but not separately as VB6.

If you like using VBA then obviously you should use it for what you want to do. Bear in mind that as far as I can see it doesn't produce executables which you could share with others, nor is there an open-source compiler such as Lazarus which can edit it, although there is some support in OpenOffice:

 http://wiki.openoffice.org/wiki/VBA_interoperability_in_OpenOffice

Also as an essentially interpreted language rather than compiled it is likely to be slower than compiled executables. But probably not enough to notice for simple applications.

I did do some early bits of Templot in VisualBasic5 before switching to Delphi. If I can find the code in my old backup drives I will post it here so that you can see if it will compile and run in VBA.

cheers,

Martin.

posted: 18 Feb 2020 23:45

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
You mentioned that idea of a row of bricks? I wonder if I could then animate my head bashing against it!

Joking aside, I'm reading through various guides and managing to get the sample codes working. But I've tried to modify one:

procedure TForm1.Button1Click(Sender: TObject);
begin
label1.caption := 'Hello World'
end;


to


procedure TForm1.Button1Click(Sender: TObject);
begin
if label1.caption := 'Hello World'
then label1.caption := 'Goodbye World'
else label1.caption := 'Hello World';

end;

it is telling me "unit1.pas(35,10) Error:incompatible types: got "untyped" expected "Boolean"

What I'm trying to do is:
'when I press that button
if it is already saying 'hello world'
then I want it to say 'goodbye world'
otherwise if it's showing something different then show 'hello world'

I can't see why that wouldn't work. I know it's a pitifully simple example and certainly not about to form Templot 3 or 4, but nevertheless from what I've read it SHOULD work...

Any pointers, please? I'm not going to try and abuse your kindness with continual questions, but this one is bugging me.

Thanks
Derek

posted: 18 Feb 2020 23:53

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:
if label1.caption:='Hello World' 
Hi Derek,

You used the assignment operator instead of equivalence. :)

That should be:

if label1.caption='Hello World'

I'm not going to try and abuse your kindness with continual questions, but this one is bugging me.
No problem. I'm happy to help if I can. :)

cheers,

Martin.

posted: 19 Feb 2020 08:20

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:

procedure TForm1.Button1Click(Sender: TObject);
begin
if label1.caption := 'Hello World'
You have used the wrong operator.   " := " assigns a value,  " = " tests for equality

http://www.prestwoodboards.com/ASPSuite/KB/Document_View.asp?QID=101809

BTDT myself somtimes. :D

Jim.

posted: 20 Feb 2020 00:49

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
Thanks both of you.

I went on to experiment with other bits and pieces yesterday- mainly substituting the instruction from the button press and seeing what each did. Most worked as expected.

I was quite pleased with myself when I worked out how to add two or more instructions in the if/then/else statement.

To a beginner such as myself, it is an easy mistake to leave that colon there as there was no reason for me to even think of removing it. But now I see a bit more of how the language is structured, it's a little easier (hence the comment above about if/then/else).

Thanks again.
Derek

posted: 20 Feb 2020 01:26

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 was quite pleased with myself when I worked out how to add two or more instructions in the if/then/else statement.
Hi Derek,

You can gain quite a lot of understanding by means of rigorous indenting of the lines, although not all programmers agree exactly how it should be done. Also by using upper case for the common Delphi properties, and lower case for your own identifiers. For example:

if hello_button.Caption='Hello World'
   then begin
          hello_button.Font.Size:=18;
          hello_button.Caption:='Goodbye World';
        end  // N.B. no semi-colon preceding an else statement, a common mistake
   else begin
          hello_button.Font.Size:=12;
          hello_button.Caption:='Hello World';
        end;

Notice also that I ensure the begin and corresponding end statements are always vertically aligned.

None of this makes any difference to the way the program compiles and runs, you could write:

if hello_button.caption='Hello World' then begin hello_button.font.size:=18; hello_button.caption:='Goodbye World'; end else begin hello_button.font.size:=12; hello_button.caption:='Hello World'; end;

and it would all work just fine. But it's very difficult to follow the logic, especially 5 years later.  :)

cheers,

Martin.

posted: 20 Feb 2020 01:56

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:
it is an easy mistake to leave that colon there as there was no reason for me to even think of removing it.
Hi Derek,

The compiler was actually telling you to do so:

unit1.pas(35,10) Error:incompatible types: got "untyped" expected "Boolean"

means that on line 35, at column 10, after the if statement, it was expecting to find an expression which it could evaluate to True or False, i.e. a Boolean* type expression, such as a=b (a either is or isn't equal to b).

Instead it found an assignment expression, setting a variable to a new value (for which there is no expression type, and certainly can't be evaluated as a True or False statement).

*http://en.wikipedia.org/wiki/George_Boole

cheers,

Martin.

posted: 2 Mar 2020 11: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
Thanks Martin

I'm making progress and it's quite enjoyable. Mostly taking bits of code and attaching it to a 'when I click the button' then this happens... but it's a quick and easy way to try out new codes I've found.


What is confusing a little bit is why some examples have multiple pages and some don't. When I used the form to generate some code (ie putting the boxes in) then it created two pages, but in the Templot developer that I downloaded, each file is just one page.


I'm also finding sometimes that if I have two unrelated aspects- ie two separate click boxes- that it doesn't work, whereas other times it does. I can't quite work out what the difference is.

It's enjoyable, especially when I struggle for ages and then something clicks in place.

Thanks for all your help with this. I'm glad I decided to have another go.

posted: 2 Mar 2020 11:41

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:
What is confusing a little bit is why some examples have multiple pages and some don't. When I used the form to generate some code (ie putting the boxes in) then it created two pages, but in the Templot developer that I downloaded, each file is just one page.


I'm also finding sometimes that if I have two unrelated aspects- ie two separate click boxes- that it doesn't work, whereas other times it does. I can't quite work out what the difference is.

It's enjoyable, especially when I struggle for ages and then something clicks in place.
Hi Derek,

You have rather lost me there. :? What do you mean by a "page" in this context? Do you mean editor tabs in Lazarus? Where are you finding these examples?

Can you post a bit of code showing these "two separate click boxes"?

I'm glad you are finding it enjoyable -- it can get a bit addictive. :)

cheers,

Martin.

posted: 3 Mar 2020 10:49

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
Yes, I think 'editor tabs' is probably what I mean.

I've found various bits and pieces of code scattered around the pages you've suggested, plus some others I've found. Not whole programmes, just a few lines- trying to see what happens when I 'trigger' them.

I will try again to put two boxes on the same form and see what happens... Ah, I've just thought, I wonder if the form builder might generate that bit of code for me so that I can see what/how...

I'll try again.

Thanks,
Derek

posted: 3 Mar 2020 12:03

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,

Each tab in the Lazarus editor displays a separate .pas unit file.

Each form in a program has its own .pas file. The form is a .lfm file with the same name as its .pas file.

The .lfm file contains the contents of the form -- buttons and boxes, their size and position, etc.

The .pas file contains the Pascal code which makes the buttons work.

Simple programs often have only one form -- one .lfm file and one .pas file.

There can also be .pas files which are not associated with a corresponding form, which contain only code functions and data.

In addition there is an eitor tab for the .lpr file. There is only one of those. It is the main program loop which links the .pas units together.

To see the .lpr file, click the Project > View Project Source menu item.

To see each .pas file, click the Project > Units... menu item, and select the .pas file from the list.

Not all the tabs need to be visible, usually you have only the ones which you are working on open.

cheers,

Martin.

posted: 5 Mar 2020 18:26

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
Thanks Martin. The explanation is clear. I'm still not sure why I can't get two buttons to work on one form as it *appears* I'm following the same procedure as you have, but clearly there's something different.

I think I've just killed Lazarus- let's see if Lazarus can rise from the dead this time.

I couldn't open the lpi files, as in the "starting Lazarus" thread, and now I'm getting "The following package failed to load: Frameviewer09 See Project-> Project Inspector."

Any ideas on the above? Perhaps I need to re-install Lazarus.

Thanks again
Derek

posted: 5 Mar 2020 18:48

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
Hmph. Please ignore the above.

I don't really know why I couldn't get it (2 buttons) to work before, but it is working now.

I'm still seeing the Project Inspector fault, but only when trying to load TemplotMEC.lpi

I shall have another go.

Derek

posted: 5 Mar 2020 18: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
DerekStuart wrote:
I couldn't open the lpi files, as in the "starting Lazarus" thread, and now I'm getting "The following package failed to load: Frameviewer09 See Project-> Project Inspector."

Any ideas on the above? Perhaps I need to re-install Lazarus.
Hi Derek,

First try re-installing the HtmlViewer package, as detailed at:

 topic 3283 - message 24933

If no joy, then a fresh install of Lazarus from the top is probably easier than trying to discover what you did to wreck it. :)

There is probably a simple solution to your two buttons problem. If you attach the .pas file here I will see what I can find.

cheers,

Martin.

posted: 6 Mar 2020 04: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

Sorry to be a bother, but there's something wrong here. Every time I try to open TemplotMEC.lpi I just get up a blank source editor screen (the first time I try to open it I get up the .lfm instead).

I've tried installing the HTML viewer but that makes no difference. When I reinstall the whole thing, it seems to work once but then stop.

Any ideas? I've tried several of the tutorials on the 'teach yourself Delphi' sites and got about half of them to work; is this Lazarus thing different?

Sorry for all the questions; no one likes to admit defeat, but... I think I'm going to try and work out Grand Unified Theory instead as it seems easier.

Yours irritated and needing to go to sleep,
Derek

NB, if I try compiling it, it seems to work OK... I just can't see any of the code at all. No tabs, nothing.
Last edited on 6 Mar 2020 04:11 by DerekStuart
posted: 6 Mar 2020 04:58

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,

Don't give up! :)

It's probably something very simple. It's just that there is a lot to take in to get started -- not only the coding but also how to use the Lazarus compiler. I'm still learning myself, as primarily a Delphi user. :?

Lazarus is very similar to Delphi, but not identical, so don't rely too much on the Delphi web sites.

If you can't see anything when Lazarus starts, it simply means that the editor isn't open. Just go to Project > Units... menu item. Select a unit from the list which appears. Click OK.

The editor will open with that unit in a tab. Repeat to open more units in more tabs.

There doesn't seem to be any way to have the editor open without any open tabs.

If starting with templotmec, you might like to look at the metric_unit. It is a small self-contained unit for the utils > metric/scale calculator function. I haven't looked at it myself for years. Just looking at it again now, I think the form could do with some toning down of the colours!

I will maybe make a bit of video showing how to install Lazarus and get started with templotmec.

cheers,

Martin.

posted: 6 Mar 2020 10:50

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
Thanks Martin
Sorry, I was getting a bit ratty with the computer (lucky the window was closed and it bounced back inside).

I think the problem is when taking bits of code and trying to effectively reverse-engineer, it doesn't work because it references data elsewhere on the tab/unit/page or even on others. I've had a successful compile green mark and then it's hit unexpected exception errors.

BTW your solution for opening the source editor worked- thanks.

I will persevere. I really do appreciate the help and encouragement. This is one of the hardest tasks I've tried taking on.

Derek

posted: 6 Mar 2020 16:30

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 had a successful compile green mark and then it's hit unexpected exception errors.
Hi Derek,

A common cause of Exceptions is to reference something which hasn't been created.

For example a very useful and much-used component is a string list. It has built-in functions for sorting and searching, and can be referenced as a list of strings, or as one long text string. And can be easily saved to, or loaded from, a file.

But it's not enough simply to declare the name of it:

var
  new_list:TStringList;

as you would with simple variables.

If you then immediately do

  new_list.Add('the first line of text');

you will get an Exception -- because the list doesn't yet exist. You must first do:

  new_list:=TStringList.Create;

which allocates memory for the list and initialises various settings. The variable new_list then contains the Pointer to it, i.e. the location of the allocated memory.

You can then add the lines, load a file into it, etc., using new_list as the reference:

   new_list.LoadFromFile(path_string+'a_text_file.txt');

Because it is an object which you created yourself, you must obey the golden rule to delete it when you have finished using it:

  new_list.Free;

which frees the allocated memory for re-use.

Otherwise your program will gradually use more and more memory until there may not be enough left in the computer to continue running.

And another common cause of Exceptions is to forget you have done that, and try to reference it again afterwards. :)

cheers,

Martin.

posted: 7 Mar 2020 14:28

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
Thanks again Martin.

There's something odd with Lazarus. I have re-installed it yet again and now it's working OK. It opened up with 1 * lpr tab and 1 * unit1 tab.

The lpr tab addresses the unit1 tab and tells it to create the form.

However, if I close that project and start a new one, the lpr tab doesn't have any references to anything and when I type it in manually it doesn't seem to find it.

Lord knows what I've done- but I've copied it all in Notepad now.

I made a simple programme with 2 forms, each with a button that when clicked, opened the other form and closed itself. However, when I reference unit2 from unit1 (in 'uses') it recognises and accepts it. But when I reference it the other way it tells me it's a circular reference and won't allow it. Is that correct?

Apologies again for all the questions. It is addictive and infuriating in equal measures at the moment.

Thanks
Derek

posted: 7 Mar 2020 15:02

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 made a simple programme with 2 forms, each with a button that when clicked, opened the other form and closed itself. However, when I reference unit2 from unit1 (in 'uses') it recognises and accepts it. But when I reference it the other way it tells me it's a circular reference and won't allow it. Is that correct?
Hi Derek,

There are 2 uses clauses.

The first one is in the interface section at the top of the unit. Don't add stuff there unless you know what you are doing and have a reason for it. You can easily create circular references which the compiler can't resolve.

The second one is lower down in the implementation section. If there isn't a uses clause there, create one:

implementation

uses

  pad_unit, colour_unit, control_room;


Put your unit references there. They won't create circular references because the scope of the implementation section is limited to this unit only.

But that means any declarations in this section need to be copied into the interface section, in order to be referenced from other units. Other units referencing this one can see only what is in its interface section.

cheers,

Martin.

posted: 7 Mar 2020 17:00

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
Sorry Martin. Last question I promise.

Are there any books you can recommend- either paper or online? I bought one from Waterstones but it's Deplhi only. I've downloaded the ebook that I *think* Jim referred to the other week- its link has moved but I found it. However, none of the examples work and I've asked on a forum and been told 'object pascal' isn't the same thing as 'freepascal'.

I'm really sorry for all the questions. You've been generous with your time but I can't expect you to keep answering these questions.

All the online examples I've found seem to be very detailed as far as pressing a button to display 'hello World' and then it's like the author has got bored and just raced straight into a list of functions- functions without context are pointless.

Time for some Ibuprofen.
Derek

posted: 7 Mar 2020 18: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:
Sorry Martin. Last question I promise.
Hi Derek,

Please don't keep apologising -- I'm happy to help. :)

It's difficult for me to advise because I learned most of my Pascal stuff 20+ years ago, and I'm still using Delphi5 from that era. I haven't kept up to date with all the developments in Delphi since, or what books and online resources are now available. That's partly because Delphi is now an expensive product for corporate applications and high-end IT professionals. I'm not one of those. :)

In the early days it was a hobbyists dream, available on magazine cover CDs, with many articles on using it for beginners and simple projects. Likewise there were many web sites for beginners, some of which are still online. The best one is probably Neil Moffatt's site:

 http://www.delphibasics.co.uk

which has simple easy-to-follow examples of most things.

This is the book from which I learned the full chapter and verse of Object Pascal:

2_071248_310000000.jpg2_071248_310000000.jpg

Mine is the 1999 edition. I have discovered that the 2002 edition from Delphi6 is still online at:

 http://docs.embarcadero.com/products/rad_studio/cbuilder6/EN/CB6_ObjPascalLangGuide_EN.pdf

As far as I can see it is almost exactly the same thing, so if you refer to page numbers in there I can see where you are.

Of course that's only the Object Pascal. It doesn't cover the Delphi VCL components. The much thicker (46 chapters) Delphi 7 Developers Guide is also still online at:

 http://docs.embarcadero.com/products/rad_studio/delphi7/D7_DevelopersGuide.pdf

There are more changes in that from my Delphi5 edition, but again most of it is the same. You don't have to read all 46 chapters -- I never have. :)

I suspect that Lazarus and FreePascal are more closely aligned to these earlier versions of Delphi than to later Delphi developments. Making them more relevant to learning Lazarus.

Those are both large PDFs -- it would be better to download them (right-click on the links) and view them in your PDF reader rather than in your browser.

cheers,

Martin.

posted: 7 Mar 2020 19:15

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
Thanks Martin. It is really appreciated.

I have learned that Lazarus is "almost 100%" Delphi7 compliant, which I learned after asking google for the $mode Delphi at the top of Templot.

The books look like just what I was after; I've noticed a couple of differences such as the extension names for files. Unlike most of the stuff I've read so far, V6 shows you the example and then explains WHAT and WHY- most just explain what.

I have one last challenge to set myself from this for the weekend.

I am using Listbox1.Items.Add('Item name'); *X in a button click procedure and it is populating the listbox just fine. However, when I try to do it automatically in the 'initialization' section, it comes up telling me it can't find the listbox.

Yet I can't see why it would find it for the button click but not the form loading.

Perhaps I'll find out in the next 1600 pages!

Thanks
Derek

posted: 7 Mar 2020 20:05

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 am using Listbox1.Items.Add('Item name'); *X in a button click procedure and it is populating the listbox just fine. However, when I try to do it automatically in the 'initialization' section, it comes up telling me it can't find the listbox.
Hi Derek,

If you look in the .lpr file, you will probably see

 Application.Initialize;

before the

 Application.CreateForm(...

statements.

You have to bear in mind that Pascal is a one-pass compiler. So everything must be declared before it can be referenced.

Application.Initialize;  runs through the initialization sections in all the units listed in the uses clause preceding it.

But at that stage the forms haven't been created, so it can't find a listbox on one of them, or anything else on them.

I tend to make very little use of the initialization sections, usually just setting up constants and suchlike which don't need to reference anything else.

For what you want to do, I would put the code to populate the listbox in the OnCreate event of the form containing it. That event is fired after the form has been created, so you can be sure of being able to reference its properties and components.

In this case, there is actually a much easier way to pre-populate a listbox -- select the listbox, and then in the Object Inspector click the ellipsis button on the Items property:

2_071457_450000000.png2_071457_450000000.png

which opens an editor in which you can enter the initial contents of the listbox. :)

cheers,

Martin.

posted: 7 Mar 2020 23:16

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 have learned that Lazarus is "almost 100%" Delphi7 compliant
Hi Derek,

I have now found the Delphi7 Quick Start booklet: 

 http://docs.embarcadero.com/products/rad_studio/delphi7/D7_QuickStart.pdf

It's not as might be expected about how to insert the CD and install the program.

It's actually 52 pages about getting started with Delphi programming. It's a lot more readable than the Developer's Guide, with many screenshots and some examples. Although the most useful chapter in the Delphi5 edition - "Your first application - a brief tutorial" seems to have been removed. :?

However, the Delphi4 (1998) edition, which includes it, is here:

 http://epdf.pub/delphi4-quick-start.html

and there is a download icon to download a PDF file.

See Chapter 3.

The downside of course is that it's not Lazarus, so some mental translation of the screenshots is needed.

cheers,

Martin.

posted: 9 Mar 2020 13: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,

Please also see:

 topic 3627

cheers,

Martin.

posted: 10 Mar 2020 19:48

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 seen it and replied, thanks.

The gentleman who wrote it has a very 'unfortunate' way of putting things.

I think this must be just a coincidence, but if it's as a result of you trying to help me by looking through their documents, I am sorry.

Derek

posted: 10 Mar 2020 21:27

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
BTW a general question. It seems the button function in Lazarus is just the grey square option with black writing and this is something it inherits from Windows.

There is talk about an add on that can overcome this. Do you know anything about it? I suppose it can be overcome by using simple pictures to represent buttons.

I'm making a bit more progress after reading those manuals, but my word did I need some ibuprofen after!

Thanks again
Derek

posted: 10 Mar 2020 22:11

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:
BTW a general question. It seems the button function in Lazarus is just the grey square option with black writing and this is something it inherits from Windows.

There is talk about an add on that can overcome this. Do you know anything about it? I suppose it can be overcome by using simple pictures to represent buttons
Hi Derek,

Sorry I don't know anything about that add-on.

Yes the standard Windows TButton control is limited to black caption text on a background determined by the user's Windows theme. Even if you set a text colour on the form, it will be black when running.

The solution is to use a TSpeedButton instead. (2nd along on the Additional tab).

Here are some TSpeedButtons on the top row in Templot:

2_101700_110000000.png2_101700_110000000.png

There are options for adding bitmaps and adjusting the layout, changing the pressed/not pressed and/or latched-down appearance, etc. They can be grouped to act as "radio" buttons, so that pressing one releases all the others. They can also be made to repeat if held down (as the blue arrows do above).

The only drawback is that these are Delphi/Lazarus graphic controls, not Windows controls, so they don't for example have a Handle, or highlight as the mouse moves over them, and they can't receive focus (which is sometimes an advantage). In practice they work just fine.

p.s. see p. 9-47 to 9-50 and 10-8 in the Developer's Guide.

cheers,

Martin.

posted: 11 Mar 2020 02:46

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
p.s. Derek,

If you were thinking of swapping to Delphi for a full business project, you can purchase some very fancy buttons and other controls from suppliers such as DevExpress and others:

 http://www.devexpress.com/products/vcl/

But I doubt they would work with Lazarus.

cheers,

Martin.





posted: 14 Mar 2020 15:24

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
Thanks Martin. As ever, I'm appreciative of your help.

I notice using TSpeedButton the background colour still remains grey, as per the normal button. This isn't an issue as it can be overlaid with 100% bitmap anyway.

I'm getting there now. Slowly!

Derek

posted: 14 Mar 2020 17:21

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 notice using TSpeedButton the background colour still remains grey, as per the normal button. This isn't an issue as it can be overlaid with 100% bitmap anyway.
Hi Derek,

I see in Lazarus (but not in Delphi5) that TSpeedButton does have a Color property -- but to make it work you must also set Transparent to False.

The default background colour is actually clBtnFace, which is the current colour set in Windows, so that it matches other Windows applications and ordinary TButtons. If the user were to change their Windows desktop theme, the SpeedButtons would change accordingly.

All TGraphicControls have an accessible Canvas property. You can therefore draw whatever you want on the button in any colour. For example on a large SpeedButton you could draw the entire Templot trackplan. :)

To do such things you need to add a handler in the SpeedButton's Paint event (in the events column on the Object Inspector):

procedure Tmy_form.my_speedbuttonPaint(Sender:TObject);

begin
  with my_speedbutton.Canvas do begin

    Brush.Color:=clYellow;
    Brush.Style:=bsSolid;
    FillRect(Rect(0,0,my_speedbutton.Width,my_speedbutton.Height));

    Font.Name:='Arial';
    Font.Size:=12;
    Font.Color:=clRed;
    TextOut(0,0,'click me');

  end;//with

end;

which would make the button colour yellow all over with the text click me on it in red, in Arial size 12, at the top-left of the button.

Note that once you do this sort of thing, you make yourself responsible for all the other built-in functions, such as drawing the borders, latched-down appearance, etc.

cheers,

Martin.

posted: 14 Mar 2020 17:30

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
p.s. Derek,

edit above, added note about Transparent.

Martin.

posted: 25 Mar 2020 13:50

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
As ever, thank you.

I have now got to the point where I'm trying out chapter 3 "Your first application."

Databases is an area of particular interest to me. I've read up a bit on connecting MySQL, SQLite and Firebird. However, the example in Delphi shows its own pre-installed test database. It also mentions a control named "TTable" which is in the data access tab; but there's nothing named similar- do you know which it is, please? The rest all seems quite straight forward on a dry run- he says...

Anyway, apart from that I hope you- and all forum users for that matter- are keeping safe in this surreal period.

Derek

posted: 25 Mar 2020 14:25

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

I've just stumbled across this site. It is well worth noting for anyone else reading this who wants to learn. Simple to follow guides and working downloadable files to see, dissect and reverse-engineer etc.

http://www.festra.com/fp/index.htm

Thanks
Derek

posted: 25 Mar 2020 20: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,

Thanks for the link, some interesting stuff there.

I regret to say that my knowledge of database programming is nil. Early versions of Delphi included the BDE (Borland Database Engine), but I never had any need for it so never learned anything about it.

I found this page which contains a lot of sample Lazarus code and may be helpful:

 http://wiki.freepascal.org/How_to_write_in-memory_database_applications_in_Lazarus/FPC

Also, this database package for Lazarus/FPC may be worth a look:

 http://wiki.freepascal.org/ZMSQL

It's open-source, so the code could be a useful guide for your own database program.

cheers,

Martin.

posted: 11 Apr 2020 13:50

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

I hope you- and everyone else here for that matter- is well.

I thought you might appreciate an update in view of all the help you've given.

I'm not about to throw in my day job (if it still exists post-corona) but I think I've become an 'advanced beginner'(!) in respect of using Lazarus for database management. I can see the fascination you mentioned before ("I wonder, if I do X can I make it do Y and will Z then work"). Many nights going to bed at dawn due to 'one last experiment.'

Anyway, that's it- I just wanted you to know your help and advice wasn't wasted. I'm not about to write Templot 4, but if anyone ever needs a database... (actually, there's an element of the disciplines used in Templot that I will need to explore in due course, so you never know.)

Again, thanks for introducing me to this fantastic hobby- which post corona might end up as my job...

Keep safe.

Derek

posted: 11 Apr 2020 22: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
Hello Derek,

Many thanks for those kind words. You may not realise how much they mean to me. I sometimes spend hours writing stuff and I often wonder if I'm wasting my time, that no-one will ever bother to read it. Especially when posting on RMweb.

I'm really pleased that you are enjoying coding. I know all about going to bed at dawn, especially when "just one more thing to try" doesn't work, and I just know that I won't be able to sleep until I have solved it. :)

Nowadays I force myself to switch off by doing something else for half an hour -- usually the dreaded OSM which can be just as much an addiction if I'm not careful. Just yesterday on my daily Boris walk I was making a careful note of the positions of the power poles in a couple of local fields because I wasn't sure I had got them marked correctly. I noticed no-one else fretting about which side of the hedge they were on. :)

stay safe,

Martin.

posted: 25 Apr 2020 13:46

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
Please never under-estimate how highly you are regarded. Don't forget if you type a response to one person, perhaps 100s will read it- either there and then or it's forever cached in search engines.

Sadly a lot of people don't really acknowledge the help they've been given; indeed, I tend to find when talking to people I 'know' a bit better that it's easier to thank them during your next post rather than have a forum full of 'thanks', 'you're welcome' and 'thanks again.' I'm sure I'm not the only one and that can often make it appear unacknowledged.


Anyway, on that subject... I am getting on quite well with the databases, indeed it's been at least a few hours since I threatened to throw the PC out the window. I jest, it's just an issue of getting out of the MS Access/ VBA habit and into a different discipline.

One thing I'm finding a blank with is basic on form data handling. I have followed a tutorial for building a calculator and it works, but I've tried to 'pick the bones' out of it to come up with a simple 'add one box to another', but I can't see why it's working. Like the database, if I can break the back of one problem it seems expanding from there on is easy. Any ideas, please?


var
Form1: TForm1;
Value1: Integer;
Value2: Integer;
Value3: Integer;

implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
{ Box3.Caption := Box1.Caption + Box2.Caption;}
{ Value1 := Box1.Caption;
Value2 := Box2.Caption;
Value3 = Value1 + Value2;}

Box1.Caption := StrtoInt (Value1);
Box2.Caption := StrtoInt (Value2);
Value3 := Value1 + Value2;
Box3.Caption := Value3;
end;



OSM? That's the open source mapping system, I believe. Funny enough I have just been playing about with something very similar- trying to plot a database of GPS co-ordinates on a google map (that database unsurprisingly is destined to be fed by a GPS sender unit). As for the 'Boris walk', it's funny how you start noticing things you don't normally notice- I found myself staring at a piece of an old wall when in Tesco trying to work out if it was part of Towcester's old railway station. (I concluded it was part of the original adjacent foundry). Sorry, I waffle on- another lockdown bad habit.

Derek

posted: 25 Apr 2020 14:40

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
Derek, thanks again for the kind words.

try
  Value1:=StrToInt(Box1.Caption);
  Value2:=StrToInt(Box2.Caption);
except
  ShowMessage('error: boxes must contain whole numbers only, no decimal point or other characters');
  EXIT;
end;


Then you need the IntToStr function, not StrToInt:

Box1.Caption := StrtoInt (Value1);
Box2.Caption := StrtoInt (Value2);
Box3.Caption := Value3;


Box1.Caption := IntToStr(Value1);
Box2.Caption := IntToStr(Value2);
Box3.Caption := IntToStr(Value3);

But what are those boxes? If they are TEdit controls, you need Box1.Text etc., not .Caption.

Caption isn't usually editable by the user.

Yes, OSM:

 http://www.openstreetmap.org

Don't ever register on there as a mapper. It will take over your life. There is no end to it as you go around your local area. Is that posting box shown in exactly the right place? Does it have the right ref number in the database? Last collection time? Now then, about the bus stops...

That old broken stile has recently been replaced with a kissing gate... And is that a fence or a hedge or bits of both...

Now I'm waffling too. :)

cheers,

Martin.

posted: 26 Apr 2020 13:56

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
Marvelous, thanks Martin.

I can see I was invoking VBA type expressions and couldn't spot it no matter how many times I read and re-read it. You were of course right about caption Vs text; I changed to TEdit boxes but didn't update it and the debugger didn't get as far as warning me before crashing over the above issues.

Last night I managed to 'translate' variables to and from date forms and store variables across forms too.

Much like my 2 questions on Freepascal forum, once you crack the basic syntax of something, working the rest out becomes easy. After reading your answer last night, I now have a *rudimentary* double entry book keeping programme, managing accounts, suppliers, customers and purchases. Only basic, but it's a "proving" concept. I think I've probably crammed into a couple of months what should take a couple of years, and that's in no small way due to your help and encouragement.

Given the time you spend on Templot, the forum, RMW, and now mapping- how do you find time to lead a life? I will be looking at OSM for this project in due course; I have experimented with Google maps, but although it's free for what I want to use, I don't like being at the 'mercy' of Google, nor relying on its APIs.

Now, I've just downloaded a demo PHP server to see if I can integrate a website with my database...

Thanks again Martin. I'm achieving something practical AND having fun. Mostly!

Derek

posted: 10 May 2020 21:50

from:

Mike Kynaston
 
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 Martin,
I have been looking round for a programming system to use on the PC, and came across this thread. Is it the Community Edition that you use for Templot or have you purchased the full blown edition?

I am interested in writing some software to control some operations on a DCC layout, and having a good background in Network design, Visual Basic, Python and PHP (god I even go back to Spectrum 64 basic!) I don't think Delphi should be beyond me, as long as I can figure out communications with the COM ports.

Mike

posted: 10 May 2020 22:14

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
Mike Kynaston wrote:
I have been looking round for a programming system to use on the PC, and came across this thread. Is it the Community Edition that you use for Templot or have you purchased the full blown edition?
Hi Mike,

I strongly advise against the Delphi Community Edition. It seems to be just a marketing exercise by Embarcadero. You will get endless nagging emails from them to buy the very expensive full version, even hinting that you are using the Community Edition outside the licence conditions. And there is no guarantee that the licence will be renewed after the first 12 months.

If you are looking to do a bit of coding, I suggest Lazarus. Free and open-source:

 http://www.lazarus-ide.org/

It's a clone of early versions of Delphi. For Templot2 I use a very early version, Delphi5 from 1998. :)

Templot3 is coded in Lazarus:

  http://sourceforge.net/projects/opentemplot/

To try running Templot3, click the T3 menu in Templot.

For a guide to getting started in Lazarus, see:

 topic 3283

p.s. I have turned you green, so that you can see this forum section:

 http://85a.co.uk/forum/view_forum.php?id=26

Anyone else? See:

 topic 3539

cheers,

Martin.

posted: 12 May 2020 03:53

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 Mike
I am well below Martin's ability, but like you, I am new to the idea of a Pascal language.

I really started this seriously only a few months ago and now I would say I'm about 90-95% of the way there with database management using Lazarus; I specifically chose this discipline as that's what I needed and there are areas of Pascal that I'm still really learning.

It's incredibly addictive. Here it is now 03:49 on Tuesday morning and I've just stopped from "...I wonder if I change this, will it do that..."

I came from a moderate level of VBA, using it to turbo-charge MS Access in the past. As part of my Pascal/Lazarus learning I have had to master PHP (a beautiful and simple language), brush up on javascript and refresh html.

Lazarus is, IMO, now a little bit of a poor relation to Delphi, but as Martin says I would absolutely steer clear of the Delphi community edition. It has a number of restrictions and muggins here was trying to work out why I had so many compile errors, only to realise that it's a restricted version.

I'd encourage you to download and try Lazarus. I am nowhere near Martin's level, but I am happy to help as I know what it's like for a beginner. I have a list of documents (mostly thanks to Martin) and several websites I've found.

Good luck. But remember it's addictive.
Derek

posted: 12 May 2020 13:55

from:

Mike Kynaston
 
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,
Thanks for the heads up on Lazaraus, I have downloaded it, so will have a look, and will take a look at your Getting Started guide. Thanks.

Mike

posted: 12 May 2020 14:01

from:

Mike Kynaston
 
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:
Hello Mike
I am well below Martin's ability, but like you, I am new to the idea of a Pascal language.

I really started this seriously only a few months ago and now I would say I'm about 90-95% of the way there with database management using Lazarus; I specifically chose this discipline as that's what I needed and there are areas of Pascal that I'm still really learning.

It's incredibly addictive. Here it is now 03:49 on Tuesday morning and I've just stopped from "...I wonder if I change this, will it do that..."

I came from a moderate level of VBA, using it to turbo-charge MS Access in the past. As part of my Pascal/Lazarus learning I have had to master PHP (a beautiful and simple language), brush up on javascript and refresh html.

Lazarus is, IMO, now a little bit of a poor relation to Delphi, but as Martin says I would absolutely steer clear of the Delphi community edition. It has a number of restrictions and muggins here was trying to work out why I had so many compile errors, only to realise that it's a restricted version.

I'd encourage you to download and try Lazarus. I am nowhere near Martin's level, but I am happy to help as I know what it's like for a beginner. I have a list of documents (mostly thanks to Martin) and several websites I've found.

Good luck. But remember it's addictive.
Derek
Hi Derek,
Thanks for the info, much appreciated.  Yes, the database side of things will be critical for what I am thinking.  I grew up in a BASIC environment, starting with a Spectrum, the Commadore 64 and later Amiga, moved to PCs and taught myself Visual Basic, then ASP and moved to PHP when ASP.Net came in, and known the basics of JavaScript.  Did do machine code for a while at one time too!  I've looked at Csharp in the past, but not to the level of being comfortable with it.  

I have been playing with the Community (free) version of VisualStudio2019.NET which has possibilities for me too.  My core requirements are to be able to communicate with and listen to the COM port, to pick Loconet packages, but also to be able to communicate with a CAN bus - as a member of MERG I am looking forward to the simplicities of CAN, which brings a lot of power in small easy packages.  But I need the PC software to tie everything together - I was thinking that Delphi, or Lazarus, might be a better option than VS2019, so a bit of testing and learning needs to be done I think!

Mike

posted: 11 Dec 2020 08:44

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
Returning to this topic to say that Embarcadero have just now posted a new Object Pascal Guide as a free download:

 http://lp.embarcadero.com/Object-Pascal-Handbook-2021?utm_source=whitepaper&utm_medium=email&utm_content=ObjectPascalHandbook2021

It includes the latest Delphi changes, but the basics should be the same as always. A lot of it (but not all) should apply equally to Lazarus.

cheers,

Martin.

posted: 12 Dec 2020 02:48

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
That's an interesting manual, thanks for sharing the link with us. It's one of those written in an easy to follow style (many aren't) and after several months without trying, it's very easy to forget how to do the basics, though I'm pleased the database controls came back to me very quickly.

One of the things I was experimenting with before I temporarily gave up is importing GPS data from a database (simulating a tracker's output) and trying to plot it on a map. Have you ever tried anything like that before or is there anything you can suggest to point me in the right direction?

It's not that I'm desperate to tackle complicated jobs yet, but having the knowledge it can be done eventually is useful.

A nice little Christmas job to re-read that book.

All the best
Derek

posted: 12 Dec 2020 10: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:
One of the things I was experimenting with before I temporarily gave up is importing GPS data from a database (simulating a tracker's output) and trying to plot it on a map. Have you ever tried anything like that before or is there anything you can suggest to point me in the right direction?
Hi Derek,

A popular format for recording GPS tracking data is in GPX files (*.gpx). There are lots of programs available for analysis, editing and plotting of GPX files.

GPX files are text-based, in XML format, so it's quite easy to parse and extract data from them in your own code.

More about the GPX format:

 http://www.topografix.com/gpx.asp

Details of the XML Schema for GPX:

 http://www.topografix.com/GPX/1/1/

Here's one of mine, opened in *Notepad++

2_120500_590000000.png2_120500_590000000.png

trkpt is a single track point, and you can see it's easy to extract the latitude and longitude figures. I can post a bit of code showing how to do that if you wish?

Converting the lat and lon to X,Y co-ordinates for plotting on a screen map at different zoom levels is the tricky bit, involving some maths.

You can enter lat and lon directly in OSM to find the map location:

2_120511_430000000.png2_120511_430000000.png


Note that for most of the UK, longitude is negative.

To get some GPX files to play with, click the GPS Traces link above.

*Notepad++ is the essential (free) text editor for programmers:

 http://notepad-plus-plus.org/

cheers,

Martin.

posted: 12 Dec 2020 16:36

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, thank you for the info.

If I've understood the process correctly:
- I use a GPS device, which I instruct where to output its data
- Say I have a server, presumably it ends in a database, which I must design
- I then convert ('parse') the data from the native format of the device to the native format of the mapping system.
- Then I would embed a map into the programme (easy enough, I think) and then by some coding magic, I import the data from the database onto map.

Once I've got to that stage, then I could set up waypoints, such as 'Martin's Town' starting from Lat1-Lat2/ Lon1-Lon2 and any trace within that location could be triggered to say "GPS1 just drove through Martin's Town", for example?


I'm not sure if I mentioned this before (probably) but I originally set out to write some software for a specific task that is badly lacking in my industry; it's not for a commission, it's purely private to prove a point. Most of it is just a basic database anyway, but things like GPS are a bit specialist.

I'll take your offer to show how to parse the data, thank you, but I need to learn a bit more of the basics before I get to that point; I was more interested at this stage to see if it can be done- which it seems it can.

Thanks
Derek

posted: 12 Dec 2020 19: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:
Once I've got to that stage, then I could set up waypoints, such as 'Martin's Town' starting from Lat1-Lat2/ Lon1-Lon2 and any trace within that location could be triggered to say "GPS1 just drove through Martin's Town", for example?
Hi Derek,

We seem to be getting two different things muddled up. :?

This is what I do and could possibly help with:

1. I take my GPS device (Satmap Active 20) out with me. At some stage I switch it to start tracking, and it records my movements until I switch tracking off. With or without tracking on, it shows me where I am on the map, and it shows the track I made as a string of red dots on the map.

2. when I get home, I transfer the tracking record, as a GPX file, from the Satmap to my computer.

3. on the computer, I use the data in the GPX to plot my route on a map. I can do that manually, or use my own program, or use other software to import the GPX and display the track on a map. (I can also use the time records in the GPX to correlate with the time recorded for my photographs, and get the geographical location for each photo.)

What you seem to want is:

1. attach a GPS tracking device to a moving object.

2. it continuously transmits its live position to a receiver.

3. at the receiver the position is shown live on a map, or used for some other purpose.

I'm sorry, I don't know anything about that process, or what data formats are used. I would be interested to learn more.

But there are dozens of commercial applications which can do that. They are used for example by online delivery services such as Amazon to show you where their driver is and how many stops away from reaching you. One such is:

 http://kiffgo.com/

(I know nothing about it, it was just the first result on Google.)

There are similar personal apps which can be installed on mobile phones, and transmit your location back home for emergencies, etc.

Generally, if something is already being done, I don't have a great interest in re-inventing someone else's wheel. That's why I spend my time mostly on Templot where there is nothing else comparable on Earth. :)

cheers,

Martin.

posted: 12 Dec 2020 20:47

from:

Rob Manchester
 
Manchester - 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,

I seem to remember seeing something on drone websites that sounds like what you want to do - maybe worth a look. There are also many farmers with fancy modern tractors that are GPS controlled so they can plough, sow and harvest without having to steer the tractor/combine manually.

As Martin points out delivery companies can have live maps that show you where the van is and when it is going to arrive with you. I buy a lot of my things from companies that use DPD for delivery and they have now stopped using the live map and just tell you what parcel number the driver is currently working on and how long he will be before arriving at your place. Maybe that were getting hijacked too often :(

Rob


posted: 12 Dec 2020 21:23

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
Rob Manchester wrote:
There are also many farmers with fancy modern tractors that are GPS controlled so they can plough, sow and harvest without having to steer the tractor/combine manually.
Hi Rob,

It's made a noticeable difference to the countryside in just the last few years -- fields filled with perfectly parallel straight lines and perfectly concentric curves:

agri_geo1_1664x1040.jpgagri_geo1_1664x1040.jpg

No doubt we will soon have GPS-generated crop circles. :)

Martin.

posted: 12 Dec 2020 21:43

from:

Rob Manchester
 
Manchester - 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,

Thanks for the picture. Potatoes ? The picture shows how important lighting is to a picture - compare the crispness of the left half of the soil with that on the right.

Rob


posted: 12 Dec 2020 21: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
Hi Rob,

Yes, potatoes. Coming soon to a packet of crisps near you. :)

Martin.

posted: 12 Dec 2020 22:58

from:

Rob Manchester
 
Manchester - 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:
Hi Rob,

Yes, potatoes. Coming soon to a packet of crisps near you. :)

Martin.
Martin,
Good job - I eat lots of crisps, usually Bovril, Salt&Vinegar and plain( with a little salt sachet ). I am rather partial to Twiglets too....

I hope the farmers have New Holland tractors ( made in UK even if they are run by an Italian ) otherwise they will start putting Brexit tax on my crisps.

Rob


posted: 18 Dec 2020 19:04

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
Thanks Martin
I've made a bit of a breakthrough in understanding the codes necessary to understand GPS output.

As far as I can see, standalone GPS trackers use a format known as NMEA and the output comes out like this:

$GPGGA,185259.858,5131.860,N,00007.412,W,1,12,1.0,0.0,M,0.0,M,,*73
$GPGSA,A,3,01,02,03,04,05,06,07,08,09,10,11,12,1.0,1.0,1.0*30
$GPRMC,185259.858,A,5131.860,N,00007.412,W,,,181220,000.0,W*6F

This is the location of the passenger footbridge at Kings Cross, platform 8.

Although I don't know how to do it- yet- I'm sure when the time comes, parsing this into the format required by a map won't be a problem. You were dead right in what you once said to me- this is addictive once you get on a roll.


Rob,
There aren't enough Twiglets on planet Earth for the both of us. I suggest instead we just collect small tree branches and dip them in Marmite.

Derek

EDIT: Clarification: As I understand it NMEA is the standard method of GPS operation for the USA's system and how some/ many GPS units work internally; this does not necessarily mean they output in this format to the end user. 


Last edited on 18 Dec 2020 19:11 by DerekStuart
posted: 18 Dec 2020 19:22

from:

Rob Manchester
 
Manchester - 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
Derek,

I assume you are refering to the Mr Bean version of Twiglets ! They are a bit chewy for my poor teeth :(

I could empty the loose bits from the bottom of Twiglets bags all day long. Look out for the Christmas drums of them on special offer in the supermarket.

Rob


posted: 19 Dec 2020 19:03

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
Rob,

I have seen those drums of Twiglets already. I DID have a drum of them somewhere last Friday- but now I have only an empty drum and an empty bottle of rum next to it.

I have no idea what happened. Must have been Father Christmas and his damned reindeers.

Derek



Templot Club > Forums > Off track > Making sense of program code in Lazarus
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