click here for a list of all existing Templot documentation
  Important Privacy Information cookie information pre-print options:    

 click image to open Templot Club in a new tab             Search           remove page highlighting
Templot club top logo
  looking for help ? -- -- --
looking for Templot? - (free)


enjoy using Templot? - 

 you are not logged in  - Login | Join

receive all messages by email: info


Recent Topics
Front Page  Search  Image Gallery  Gallery Upload  My Account  Members  SourceForge  TemplotMEC  Help  
make a donation  
please click: important information for new members and first-time visitors Templot Companion - User Guide
            messages archive on Yahoo
page trail:  Templot Club > Forums > Off track > Making sense of program code in Lazarus
Templot web site

                 Making sense of program code in Lazarus
  Page:    1  2  Next Page Last Page      
 Start new topic   Reply blank   Printer friendly 
  Rate this topic  
AuthorMessage
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
1st message | this message only posted: 8 Feb 2020 14:31
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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

__________
message ref: 28978

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
2nd message | this message only posted: 8 Feb 2020 14:48
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 28979

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
3rd message | this message only posted: 8 Feb 2020 14:50
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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:

 http://85a.co.uk/forum/view_topic.php?id=3539&forum_id=1

The original "starting with Lazarus" topic is at:

 http://85a.co.uk/forum/view_topic.php?id=3283&forum_id=26

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

 https://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.

__________
message ref: 28980

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
4th message | this message only posted: 8 Feb 2020 15:04
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 28981

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
5th message | this message only posted: 8 Feb 2020 15:21
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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.

__________
message ref: 28982

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
6th message | this message only posted: 14 Feb 2020 08:54
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
Hi Derek,

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

 https://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.

__________
message ref: 29023

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
7th message | this message only posted: 16 Feb 2020 11:49
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29037

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
8th message | this message only posted: 16 Feb 2020 14:01
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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.

__________
message ref: 29040

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
9th message | this message only posted: 16 Feb 2020 22:19
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29043

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
10th message | this message only posted: 16 Feb 2020 23:03
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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. 

__________
message ref: 29044

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
11th message | this message only posted: 17 Feb 2020 16:15
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29046

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
12th message | this message only posted: 17 Feb 2020 17:11
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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:

 https://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.

__________
message ref: 29047

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
13th message | this message only posted: 18 Feb 2020 22:45
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29056

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
14th message | this message only posted: 18 Feb 2020 22:53
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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.

__________
message ref: 29057

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
15th message | this message only posted: 19 Feb 2020 07:20
 PM  Reply with quote  Reply blank 
from:
Jim Guthrie
United Kingdom

 

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

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

BTDT myself somtimes. :D

Jim.

__________
message ref: 29060

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
16th message | this message only posted: 19 Feb 2020 23:49
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29064

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
17th message | this message only posted: 20 Feb 2020 00:26
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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.

__________
message ref: 29065

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
18th message | this message only posted: 20 Feb 2020 00:56
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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).

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

cheers,

Martin.

__________
message ref: 29066

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
19th message | this message only posted: 2 Mar 2020 10:09
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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.
__________
message ref: 29149

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
20th message | this message only posted: 2 Mar 2020 10:41
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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.

__________
message ref: 29151

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
21st message | this message only posted: 3 Mar 2020 09:49
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29164

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
22nd message | this message only posted: 3 Mar 2020 11:03
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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.

__________
message ref: 29165

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
23rd message | this message only posted: 5 Mar 2020 17:26
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29168

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
24th message | this message only posted: 5 Mar 2020 17:48
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29169

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
25th message | this message only posted: 5 Mar 2020 17:54
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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:

 http://85a.co.uk/forum/view_topic.php?id=3283&forum_id=26#p24933

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.

__________
message ref: 29170

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
26th message | this message only posted: 6 Mar 2020 03:08
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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.
__________
message ref: 29171

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
27th message | this message only posted: 6 Mar 2020 03:58
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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.

__________
message ref: 29173

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
28th message | this message only posted: 6 Mar 2020 09:50
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29175

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
29th message | this message only posted: 6 Mar 2020 15:30
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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.

__________
message ref: 29177

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
30th message | this message only posted: 7 Mar 2020 13:28
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29180

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
31st message | this message only posted: 7 Mar 2020 14:02
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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.

__________
message ref: 29181

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
32nd message | this message only posted: 7 Mar 2020 16:00
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29182

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
33rd message | this message only posted: 7 Mar 2020 17:20
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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:



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.

__________
message ref: 29183

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
34th message | this message only posted: 7 Mar 2020 18:15
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29184

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
35th message | this message only posted: 7 Mar 2020 19:05
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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:



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

cheers,

Martin.

__________
message ref: 29185

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
36th message | this message only posted: 7 Mar 2020 22:16
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
DerekStuart wrote: I have learned that Lazarus is "almost 100%" Delphi7 compliantHi 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:

 https://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.

__________
message ref: 29186

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
37th message | this message only posted: 9 Mar 2020 12:59
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
Hi Derek,

Please also see:

 http://85a.co.uk/forum/view_topic.php?id=3627&forum_id=26

cheers,

Martin.

__________
message ref: 29191

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
38th message | this message only posted: 10 Mar 2020 18:48
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29196

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
39th message | this message only posted: 10 Mar 2020 20:27
 PM  Reply with quote  Reply blank 
from:
DerekStuart
United Kingdom

 

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
__________
message ref: 29198

 
 Clicked a link? Wrong message? Wait until the page has finished loading, click in the address bar and then press the Enter key. This is a timing bug in some browsers.
40th message | this message only posted: 10 Mar 2020 21:11
 PM  Reply with quote  Reply blank 
from:
Martin Wynne
West Of The Severn, United Kingdom



view images in gallery
view images as slides

Please do not send requests for help direct to me via email or PM.

Post your questions on the forum where everyone can see them and add helpful replies.
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:



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.

__________
message ref: 29199

 
This is topic ID = 3607     Page created at 09:21 (local time) Page:    1  2  Next Page Last Page    
You can type a quick reply to this topic here.

Click in the box to begin.


But to reply to an individual message, or to include images, attachments and formatted text, use the reply buttons on each message above.

To start a new topic in this forum, click the Start new topic button below.
To start a new topic in a different forum, click the Forum Jump drop-down list below.

             Start new topic 

 click to jump to a different forum:     Back to top of page

Templot Club > Forums > Off track > Making sense of program code in Lazarus
about Templot Club

list recently active topics 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